Skip to content

Instantly share code, notes, and snippets.

@farooqkz
Created December 29, 2017 10:13
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 farooqkz/400a2c1dab62bb5951ef6e95b7e3b898 to your computer and use it in GitHub Desktop.
Save farooqkz/400a2c1dab62bb5951ef6e95b7e3b898 to your computer and use it in GitHub Desktop.
A small script to get my public IP from my router/modem
import telnetlib
PASSWORD = "admin" # change these two
ADDR = "192.168.1.1"
t = telnetlib.Telnet(host=ADDR)
t.read_until("Password:".encode())
t.write((PASSWORD + "\r\n").encode())
t.read_until("TP-LINK> ".encode())
t.write("show wan status\r\n".encode())
data = t.read_until("TP-LINK> ".encode()).decode()
t.write("exit\r\n".encode())
t.close
for line in data.split("\r\n"):
if "Ip" in line:
print(line.split()[-1], end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment