Skip to content

Instantly share code, notes, and snippets.

@oscar-c
Created July 29, 2018 14:57
Show Gist options
  • Save oscar-c/178ac28495d8f2319323bedf8ccf5e8a to your computer and use it in GitHub Desktop.
Save oscar-c/178ac28495d8f2319323bedf8ccf5e8a to your computer and use it in GitHub Desktop.
Check if iPhone can receive multicast packages. If not, send large amount of packages to force the "channel" open.
#!/bin/bash
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ether=[iPhone's MAC address]
iface=[interface via witch the host connects to the iPhone]
mdns_ip=224.0.0.251 #the multicast address used by mDNS
#lookup iPhone's IP from its MAC address
ip_raw=$(arp -n -H ether -i $iface | grep $ether )
if [[ -z "$ip_raw" ]]
then
broadcast_ip=$(ifconfig $iface | sed -En 's/.*broadcast (addr:)?(([0-9]*\.){3}[0-9]*)$/\2/p')
ping -c 3 -b $broadcast_ip > /dev/null 2>&1
ip_raw=$(arp -n -H ether -i $iface | grep $ether )
fi
ip=$(echo $ip_raw | tr -s ' ' | cut -d ' ' -f1)
if ping -c 1 $ip &> /dev/null
then
:
else
#iPhone not reachable
exit
fi
result=$(ping -c 3 $mdns_ip | grep -F $ip)
iter=1
while [[ -z $result ]] && [[ $iter -lt 12 ]]; do
#send large amount of ICMP packages to iPhone
result=$(sudo ping -c 10000 -i 0.001 $mdns_ip | grep -F $ip)
echo still congested, tried $iter time\(s\)
((iter++))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment