Created
May 14, 2020 04:29
-
-
Save phanthaihuan/f81deec00d69b3b93740afa31812dc9a to your computer and use it in GitHub Desktop.
How to get private Ip and public Ip in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def getIp(): | |
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("google.com",80)) | |
out = (s.getsockname()[0]) | |
s.close() | |
return out | |
def getPublicIp(): | |
import urllib2 | |
URL = "http://ifconfig.cc" | |
f = urllib2.urlopen(URL) | |
ip = f.read() | |
return ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment