Skip to content

Instantly share code, notes, and snippets.

@louisroyer
Created August 1, 2023 18:44
Show Gist options
  • Select an option

  • Save louisroyer/7c7fa43613c8f8eb2ad0fbe997cefa0a to your computer and use it in GitHub Desktop.

Select an option

Save louisroyer/7c7fa43613c8f8eb2ad0fbe997cefa0a to your computer and use it in GitHub Desktop.
Get IP addresses (livebox)
#!/usr/bin/env python3
import subprocess
import netifaces
import ipaddress
INTERFACE = 'enxb827eba3323d'
ipv4 = subprocess.check_output('./livebox.sh').decode('utf-8').strip()
for ip in netifaces.ifaddresses(INTERFACE)[10]:
ip_i = ipaddress.ip_address(ip['addr'])
if ip_i.version == 6 and ip_i.is_global:
ipv6 = ip['addr']
break
#!/usr/bin/env bash
LIVEBOX_PASSWORD=password_to_define_here
TMP_DIR=$(mktemp -d)
contextID=$(curl -s -X POST -c "$TMP_DIR/livebox-cookie" -H 'Content-Type: application/x-sah-ws-4-call+json' -H 'Authorization: X-Sah-Login' -d "{\"service\":\"sah.Device.Information\",\"method\":\"createContext\",\"parameters\":{\"applicationName\":\"so_sdkut\",\"username\":\"admin\",\"password\":\"$LIVEBOX_PASSWORD\"}}" http://livebox.home/ws |jq -r '.data.contextID')
curl -s -b "$TMP_DIR/livebox-cookie" -X POST -H 'Content-Type: application/x-sah-ws-4-call+json' -H "X-Context: $contextID" -d "{\"service\":\"NMC\",\"method\":\"getWANStatus\",\"parameters\":{}}" http://livebox.home/ws|jq '.data.IPAddress' -r
curl -s -b "$TMP_DIR/livebox-cookie" -X POST http://livebox.home/logout
rm -rf "$TMP_DIR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment