Skip to content

Commit

Permalink
0.5
Browse files Browse the repository at this point in the history
argument change: local > ether
public IP alternates
option to input public IP if already known
output: mDNS > NAT-PMP
  • Loading branch information
JayBrown committed Oct 29, 2020
1 parent 62f9144 commit 94fef21
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 14 deletions.
20 changes: 14 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ myip
macOS CLI (shell script) to print public & local IP, network and DNS information, geolocation, address, map links, and share location information via Messages or Mail


myip [ARG(s)]
myip [--ip=<IP address>] [ARG(s)]

OPTION

--ip= : input your public IP, if it is already known

OUTPUT ARGUMENTS

ip : public IP only

net : public & local IPs and related info
net : public IPs and related info incl. NAT-PMP
bt : torrent IP address (requires transmission CLI & an IP tracking torrent)
local : additional local data like hostname, MAC addresses, SSID etc.
ether : additional local data like network IPs, hostname, MAC addresses, SSID etc.
dns : public & local DNS IPs, local resolvers & related info
loc : coordinates & country of public IPs (only with 'net' or 'dns')
geo : local geolocation (latitude & longitude)
addr : local geolocation (address)
map : print URLs to open local geolcation in Apple Maps, OSM or Google Maps

all : all of the above

OTHER ARGUMENTS

msg : share geolocation & address via Apple Messages (requires terminal-share CLI)
mail : share geolocation & address via Apple Mail (requires terminal-share CLI)
Expand All @@ -27,7 +35,7 @@ myip [ARG(s)]

Optional requisites:

terminal-share: https://github.com/mattt/terminal-share
transmission-cli: https://transmissionbt.com – install manually or with: brew install transmission-cli
(1) terminal-share: https://github.com/mattt/terminal-share
(2) transmission-cli: https://transmissionbt.com – install manually or with: brew install transmission-cli

supported tracking torrent available at: https://ipleak.net (manually add with transmission-remote)
Supported tracking torrent available at: https://ipleak.net (manually add with transmission-remote)
71 changes: 63 additions & 8 deletions myip
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
#!/bin/zsh
# shellcheck shell=bash

# myip v0.4
# myip v0.5

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/opt/local/bin:/opt/sw/bin:/sw/bin:"$HOME"/.local/bin:"$HOME"/bin:"$HOME"/local/bin

process="myip"
vno="0.4"

_simple-ip () {
icount=0
while true
do
[[ $icount -eq 3 ]] && break
publicip=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null)
[[ $publicip ]] && break
sleep 1
((icount++))
done
if ! [[ $publicip ]] ; then
publicip=$(curl -sL --connect-timeout 10 --max-time 3 ipinfo.io/ip 2>/dev/null)
fi
if ! [[ $publicip ]] ; then
publicip=$(curl -sL --connect-timeout 10 --max-time 3 icanhazip.com 2>/dev/null)
fi
}

_ip () {
if $offline ; then
echo -e "Public IP:\t-"
else
publicip=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null)
if ! $ipopt ; then
_simple-ip
fi
if [[ $publicip ]] ; then
echo -e "Public IP:\t$publicip"
publicname=$(dig +short -x "$publicip" 2>/dev/null | sed 's/\.$//')
Expand Down Expand Up @@ -59,7 +79,7 @@ _ip () {
done
! [[ $mdnsip ]] && mdnsip="-"
[[ $mdnsip == "0.0.0.0" ]] && mdnsip="0.0.0.0 [tunnel]"
echo -e "mDNS IP:\t$mdnsip"
echo -e "NAT-PMP IP:\t$mdnsip"
gateway=$(echo "$routestat" | awk '/gateway:/ {print $2}')
if ! [[ $gateway ]] ; then
arp_raw=$(arp -a 2>/dev/null | head -1)
Expand Down Expand Up @@ -401,13 +421,19 @@ EOG

_help () {
read -d '' helpdoc <<"EOH"
myip [ARG(s)]
myip [--ip=<IP address>] [ARG(s)]
OPTION
--ip= : input your public IP, if it is already known
OUTPUT ARGUMENTS
ip : public IP only
net : public & local IPs and related info
net : public IPs and related info incl. NAT-PMP
bt : torrent IP address (requires transmission CLI & an IP tracking torrent)
local : additional local data like hostname, MAC addresses, SSID etc.
ether : additional local data like network IPs, hostname, MAC addresses, SSID etc.
dns : public & local DNS IPs, local resolvers & related info
loc : coordinates & country of public IPs (only with 'net' or 'dns')
geo : local geolocation (latitude & longitude)
Expand All @@ -416,6 +442,8 @@ myip [ARG(s)]
all : all of the above
OTHER ARGUMENTS
msg : share geolocation & address via Apple Messages (requires terminal-share CLI)
mail : share geolocation & address via Apple Mail (requires terminal-share CLI)
Expand All @@ -437,8 +465,29 @@ address=false
share=false
message=false
email=false
ipopt=false

if [[ $1 == "--ip="* ]] ; then
publicip=$(echo "$1" | awk -F"=" '{print $2}')
if ! [[ $publicip ]] ; then
echo -e "ERROR: IP address input missing!\n" >&2
_help
exit 1
fi
if ! echo "$publicip" | grep -o "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" &>/dev/null ; then
echo -e "ERROR: $publicip has the wrong format!\n" >&2
_help
exit 1
fi
shift
ipopt=true
fi

if ! [[ $1 ]] ; then
if $ipopt ; then
echo -e "Public IP:\t$publicip"
exit 0
fi
simpleip=true
else
argsn="$#"
Expand All @@ -464,6 +513,10 @@ else
ip)
simpleip=true
if [[ $argsn -eq 1 ]] ; then
if $ipopt ; then
echo -e "Public IP:\t$publicip"
exit 0
fi
break
else
shift
Expand All @@ -490,7 +543,7 @@ else
torrent=true
shift
;;
local)
ether)
localdata=true
shift
;;
Expand Down Expand Up @@ -563,7 +616,9 @@ if ! ping -q -c 1 1.1.1.1 &>/dev/null ; then
offline=true
fi
if $simpleip ; then
publicip=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null)
if ! $ipopt ; then
_simple-ip
fi
! [[ $publicip ]] && publicip="-"
echo -e "Public IP:\t$publicip"
fi
Expand Down

0 comments on commit 94fef21

Please sign in to comment.