Created
September 8, 2012 11:41
-
-
Save nilbot/3674056 to your computer and use it in GitHub Desktop.
GEt External IP from router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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