Requirements
opensshshould be installed on both devices.sshddaemon should be started on both devices.- To connect to
linuxon IP192.168.1.1on port80.
ssh -p 80 linux@192.168.1.1Some useful commands.
arp -vto see the connected devices on the network.ifconfig wlan0to find the ipaddress of your device.whoamito find the username of your devicenmap localhostto 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-apiand theTermux:APIapplication to interact with android API. - Install
shizukuand setuprishwith 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
sftpmode, typetercon file, and usegetandputcommands to send and receive files.