matts0613

Myip.py

Mar 22nd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. import socket
  2. from urllib import urlopen
  3.  
  4.  
  5. def public_ip():
  6.     read_res = urlopen('http://ipecho.net/plain').read()
  7.     return read_res.decode('utf-8')
  8.  
  9.  
  10. def local_ip():
  11.     return socket.gethostbyname(socket.gethostname())
  12.  
  13.  
  14. if __name__ == "__main__":
  15.     print("Getting public and local IP...")
  16.     print("Public IP: {}\nLocal IP: {}".format(public_ip(), local_ip()))
Advertisement
Add Comment
Please, Sign In to add comment