سلام
#!/usr/bin/env python
import sys
import telnetlib
HOST = "192.168.1.1"
USER = "admin"
PASSWORD = "admin"
if len(sys.argv) < 2:
sys.exit()
_command = sys.argv[1]
tn = telnetlib.Telnet(HOST)
tn.read_until("login : ",1)
tn.write(USER.encode('utf-8') + "\r\n")
tn.read_until("PASSWORD : ",1)
tn.write(PASSWORD.encode('utf-8') + "\r\n")
if _command == "reboot":
tn.write(b"reboot\n")
if _command == "wan":
if len(sys.argv) < 3:
sys.exit()
Sub_command = sys.argv[2]
if Sub_command == "on":
tn.write(b"wan modify PVC:0/35 pppoe 0 35 LLC nat enable username password dialup AlwaysOn\n")
if Sub_command == "off":
tn.write(b"wan modify PVC:0/35 pppoe 0 35 LLC nat disable username password dialup Manual\n")
if _command == "wlan":
if len(sys.argv) < 3:
sys.exit()
Sub_command = sys.argv[2]
if Sub_command == "on":
tn.write(b"wlan enable\n")
if Sub_command == "off":
tn.write(b"wlan disable\n")
if _command == "lan":
if len(sys.argv) < 3:
sys.exit()
Sub_command = sys.argv[2]
if Sub_command == "show":
tn.write(b"lan showmac\n")
if Sub_command == "off":
tn.write(b"lan 1 disable\n")
tn.write(b"exit\n")
tn.read_until("exit")
می خوام خروجی این بخش(نمایش مک آدرس های متصل به مودم ) در اسکریپت بالا در ترمینال و فایل چاپ و نشان داده بشه
if _command == "lan":
if len(sys.argv) < 3:
sys.exit()
Sub_command = sys.argv[2]
if Sub_command == "show":
tn.write(b"lan showmac\n")
if Sub_command == "off":
tn.write(b"lan 1 disable\n")
با اجرای ./adsl.py lan show
مک آدرس افراد متصل به مودم من چاپ و نشان داده بشه
if _command == "lan":
if len(sys.argv) < 3:
sys.exit()
Sub_command = sys.argv[2]
if Sub_command == "show":
tn.write(b"lan showmac\n")
if Sub_command == "off":
tn.write(b"lan 1 disable\n")
print ?