File: sample-get-ip-from-fritzbox

package info (click to toggle)
ddclient 3.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,284 kB
  • sloc: perl: 14,597; sh: 916; makefile: 146; xml: 55
file content (21 lines) | stat: -rwxr-xr-x 1,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# 
# Script to fetch IP from fritzbox
#
# Contributed by @Rusk85 in request #45
# Script can be used in the configuration by adding
#
#    use=cmd, cmd=/etc/ddclient/get-ip-from-fritzbox
#
# All credits for this one liner go to the author of this blog:
# http://scytale.name/blog/2010/01/fritzbox-wan-ip
# Disclaimer: It might be necessary to make the script executable

# Set default hostname to connect to the FritzBox
: ${FRITZ_BOX_HOSTNAME:=fritz.box}

curl -s -H 'Content-Type: text/xml; charset="utf-8"' \
  -H 'SOAPAction: urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress' \
  -d '<?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:GetExternalIPAddress xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /></s:Body></s:Envelope>' \
  "http://$FRITZ_BOX_HOSTNAME:49000/igdupnp/control/WANIPConn1" | \
  grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'