Requirements
openssh
should be installed on both devices.sshd
daemon should be started on both devices.- To connect to
linux
on IP192.168.1.1
on port80
.
ssh -p 80 linux@192.168.1.1
Some useful commands.
arp -v
to see the connected devices on the network.ifconfig wlan0
to find the ipaddress of your device.whoami
to find the username of your devicenmap localhost
to see the running hosts on the localhost.arp -a | awk '{print $2}' | tr -d "()"
to see the IPaddress of all devices connected to the local network.
For more functionality
- Install
termux-api
and theTermux:API
application to interact with android API. - Install
shizuku
and setuprish
with Termux to use more functionalities provided byADB
.
Dependencies
openssh
sshpass
fzf
gawk
nmap
arp
egrep
grep
netcat-openbsd
Script
Connects termux with other devices via ssh, so tercon
, move it to .local/bin
#!/bin/bash
# ╻┏┓╻╻╺┳╸
# ┃┃┗┫┃ ┃
# ╹╹ ╹╹ ╹
# config file
config_file="$HOME/.config/tercon/config.sh"
# sourcing config file.
source $config_file
# Clearing the screen
clear
echo "Scanning..."
# ╻ ╻┏━┓┏━┓╻┏━┓┏┓ ╻ ┏━╸┏━┓
# ┃┏┛┣━┫┣┳┛┃┣━┫┣┻┓┃ ┣╸ ┗━┓
# ┗┛ ╹ ╹╹┗╸╹╹ ╹┗━┛┗━╸┗━╸┗━┛
# Variables
arg1=$1
argf=$2
# full path of the file
if [ $argf ]; then
arg2="$(readlink -f $argf)"
fi
# Devices ip list
if [ "$iplist" == "none" ]; then
iplist="$(arp -a | awk '{print $2}' | tr -d "()")"
fi
# ┏━╸╻ ╻┏┓╻ ┏━╸╻╻ ┏━╸
# ┣╸ ┃ ┃┃┗┫ ┣╸ ┃┃ ┣╸
# ╹ ┗━┛╹ ╹ ╹ ╹┗━╸┗━╸
# Making a function that sends a file
function send () {
if [ "$password" == "none" ]; then
invoke="scp -P $port $arg2 $whoami@"
else
invoke="sshpass -p "$password" scp -P $port $arg2 $whoami@"
fi
# Iterating over the list of ip addresses.
for item in $iplist
do
# Using "netcat-openbsd" to see if the ssh port is available.
nc -w 2 $item $port
if [ $? -eq 0 ]
then
# Echoing out the available IP.
echo "IP: $item"
break
fi
done
# Running the command to send the file
$invoke$item:$send_path
# Sending the file to another path.
if [ "$send_path2" != "none" ]; then
$invoke$item:$send_path2
fi
}
# ┏━╸╻ ╻┏┓╻ ┏━┓┏━╸┏┓╻╺┳┓
# ┣╸ ┃ ┃┃┗┫ ┗━┓┣╸ ┃┗┫ ┃┃
# ╹ ┗━┛╹ ╹ ┗━┛┗━╸╹ ╹╺┻┛
# Making a function that connects to sftp.
function file () {
if [ "$password" == "none" ]; then
invoke="sftp -p $port $whoami@"
else
invoke="sshpass -p "$password" sftp -P $port $whoami@"
fi
# Iterating over the list of ip addresses.
for item in $iplist
do
# Using "netcat-openbsd" to see if the ssh port is available.
nc -w 2 $item $port
if [ $? -eq 0 ]
then
# Echoing out the available IP.
echo "IP: $item"
break
fi
done
# Running the command to connect to sftp
$invoke$item
}
# ┏━┓┏━╸┏┓╻╺┳┓
# ┗━┓┣╸ ┃┗┫ ┃┃
# ┗━┛┗━╸╹ ╹╺┻┛
# If the second argument is "send" use function send.
if [ "$arg1" == "send" ]; then
if [ -f "$arg2" ]; then
send
echo "Sucessfully Sent! $argf"
else
echo "Sending $argf failed!"
exit
fi
exit
# ┏━╸╻╻ ┏━╸
# ┣╸ ┃┃ ┣╸
# ╹ ╹┗━╸┗━╸
# If the second argument is "file" use function file.
elif [[ "$arg1" == "file" ]]; then
file
exit
fi
# ┏┳┓┏━┓╻┏┓╻
# ┃┃┃┣━┫┃┃┗┫
# ╹ ╹╹ ╹╹╹ ╹
# The command that should run to connect to ssh.
main () {
if [ "$password" == "none" ]; then
invoke="ssh -p $port -o StrictHostKeyChecking=no $whoami@"
else
invoke="sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no $whoami@"
fi
# Iterating over each line from $iplist, which consists of the IP addresses that
# are working on the local network.
# and cheching if the ssh port is available to connect.
for item in $iplist
do
# Using "netcat-openbsd" to see if the ssh port is available.
nc -w 2 $item $port
if [ $? -eq 0 ]
then
# Echoing out the available IP.
echo "IP: $item"
break
fi
done
# Running the command to connect to ssh
$invoke$item
}
main
Config file
Configuration file for tercon
, move it to .config/tercon/config.sh
# Username on Termux
whoami="linux"
# Password on Termux (Don't set password for better security)
# To make it ask for password to connect.
password="<password>" # Comment this line and uncomment the line below.
# password="none"
# Port in which the sshd daemon is running,
port="80"
# set if the ip is static
iplist="none"
# iplist="192.168.1.01"
# path on termux to send the file to.
send_path="tercon/recieved/"
# Second send path.
send_path2="storage/shared/Applications/Termux/shared/"
# send_path2="none"
Usage
- To connect to
ssh
, just typetercon
. - To send files, type
tercon send <filename_having_no_spaces>
. Currently files with space in their names are unsupported. - To get into file transfer
sftp
mode, typetercon file
, and useget
andput
commands to send and receive files.