Show Local and Internet Ip
Show Local and Internet Ip
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 1)) # connect() for UDP doesn't send packets
local_ip_address = s.getsockname()[0]
print(local_ip_address)
import os
print(os.system('ipconfig'))
import socket
def get_ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(0)
try:
# doesn't even have to be reachable
s.connect(('10.254.254.254', 1))
IP = s.getsockname()[0]
except Exception:
IP = '127.0.0.1'
finally:
s.close()
return IP
print(get_ip())
import requests
data = requests.get("http://wikipedia.com").headers
print (data["x-client-ip"])
import requests, re
data = re.search('"([0-9.]*)"',
requests.get("http://ip.jsontest.com/").text).group(1)
print (data)
f = requests.request('GET', 'http://myip.dnsomatic.com')
ip = f.text
def get_public_ip():
import re
data = str(requests.get('http://checkip.dyndns.com/').text)
# print(data)
return re.compile(r'Address: (\d+.\d+.\d+.\d+)').search(data).group(1)
public_ip = get_public_ip()
print(public_ip)