Find Phone

From UbuntuPhone
Jump to navigation Jump to search

If you want to ssh into your phone and you don't know it's IP address you can use this script to find it, note that you need to set a couple of environmental variables first and also you need to supply the subnet (automating this would be an improvement):

#!/bin/bash

# This is a script to find a device on a LAN by it's Mac address

if [[ $1 ]]; then
  SUBNET=$1
else
  /sbin/ifconfig
  echo "Please supply the subnet, eg: $0 192.168.0.0/24"
  exit
fi

if [[ $PHONE_MAC ]]; then
  echo Mac:   $PHONE_MAC 
else
  echo You need to set the PHONE_MAC environmental variable to 
  echo the Mac address of your phone, eg add the following to 
  echo your ~/.bashrc:
  echo
  echo export PHONE_MAC="10:10:10:10:10:10"
  exit
fi

if [[ $PHONE_IFACE ]]; then
  echo Iface: $PHONE_IFACE 
else
  echo You need to set the PHONE_IFACE environmental variable to 
  echo the network interface the phone can be reached on, eg add 
  echo the following to your ~/.bashrc:
  echo
  echo export PHONE_IFACE="wlan0"
  exit
fi

# Nmap and arp scan the network
sudo nmap -sP $SUBNET > /dev/null
PHONE_IP=$(sudo arp-scan -I $PHONE_IFACE $SUBNET | grep $PHONE_MAC | awk '{print $1}')

if [[ $PHONE_IP ]]; then
  echo IP:    $PHONE_IP 
else
  echo "Sorry the phone couldn't be found"
fi

exit