Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. from telnetlib import Telnet
  3.  
  4. HOST = "192.168.1.1"
  5. USER = "root"
  6. PASSWORD = ""
  7. IFACE = "ra0"
  8.  
  9. def cmd_switch_wireless(ensoapi):
  10. "Turn wi-fi on/off"
  11. tn = Telnet(HOST)
  12. tn.read_until("login: ")
  13. tn.write(USER + "\n")
  14. tn.read_until("Password: ")
  15. tn.write(PASSWORD + "\n")
  16. tn.write("".join(("ifconfig ", IFACE, "\n")))
  17.  
  18. tn_out = tn.read_until("Interrupt")
  19.  
  20. cmd = ""
  21.  
  22. if tn_out.find(" UP ") != -1:
  23. cmd = " down"
  24. else:
  25. cmd = " up"
  26.  
  27. if len(cmd) != 0:
  28. tn.write("".join(("ifconfig ", IFACE, cmd, "\n")))
  29.  
  30. tn.write("exit\n")
  31. tn.read_all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement