Advertisement
lululombard

IP address Python

Apr 16th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import subprocess
  2. error = "Aucune IP disponible"
  3. try:
  4.     ip = str(subprocess.check_output("ifconfig wlan0|grep inet", shell=True))
  5. except:
  6.     ip = error
  7. count = ip.count(":")
  8. if count == 3:
  9.     ip = ip.split(":")
  10.     ip = ip[1].split(" ")
  11.     ip = ip[0]
  12. else:
  13.     try:
  14.         ip = str(subprocess.check_output("ifconfig eth0|grep inet", shell=True))
  15.     except:
  16.         ip = error
  17.     count = ip.count(":")
  18.     if count == 3:
  19.         ip = ip.split(":")
  20.         ip = ip[1].split(" ")
  21.         ip = ip[0]
  22.     else:
  23.         ip = error
  24. print(ip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement