matts0613 icon

Myip.py

matts0613 | PRO | 03/22/17 11:55:36 PM UTC | 0 ⭐ | 265 👁️ | Never ⏰ | []
Python |

360 B

|

None

|

0 👍

/

0 👎

import socket
from urllib import urlopen
 
 
def public_ip():
    read_res = urlopen('http://ipecho.net/plain').read()
    return read_res.decode('utf-8')
 
 
def local_ip():
    return socket.gethostbyname(socket.gethostname())
 
 
if __name__ == "__main__":
    print("Getting public and local IP...")
    print("Public IP: {}\nLocal IP: {}".format(public_ip(), local_ip()))

Comments