Skip to content

Instantly share code, notes, and snippets.

@nilbot
Created September 8, 2012 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilbot/3674056 to your computer and use it in GitHub Desktop.
Save nilbot/3674056 to your computer and use it in GitHub Desktop.
GEt External IP from router
#!/bin/bash
FBIP=192.168.3.1
NETCAT=`which nc`
[ -z "$NETCAT" ] && NETCAT=`which netcat`
[ -z "$NETCAT" ] && exit 1
INTERFACE_NS="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
WANIP_NS="urn:schemas-upnp-org:service:WANIPConnection:1"
NS="$WANIP_NS"
REQUEST="GetExternalIPAddress"
SED='/^<NewExternalIP/ s,</\?NewExternalIPAddress>,,gp'
BODY="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">
<s:Body><u:$REQUEST xmlns:u=$NS /></s:Body>
</s:Envelope>
"
LENGTH=`echo -n "$BODY" | wc -c`
( $NETCAT $FBIP 49000 | sed -ne "$SED" ) <<EOF
POST /upnp/control/WANCommonIFC1 HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Connection: close
HOST: $FBIP:49000
Content-Length: $LENGTH
SOAPACTION: "$NS#$REQUEST"
$BODY
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment