23 lines
575 B
Python
23 lines
575 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
'''
|
||
|
/***********************************************/
|
||
|
/* Script para obtener mi IP interna y externa */
|
||
|
/***********************************************/
|
||
|
'''
|
||
|
|
||
|
from socket import gethostbyname, gethostname
|
||
|
from urllib.request import urlopen
|
||
|
import json
|
||
|
|
||
|
with urlopen("https://ipwho.is/?fields=ip") as response:
|
||
|
body = json.loads(response.read()) # {'ip': 'xxx.000.000.000'}
|
||
|
|
||
|
ip = body['ip']
|
||
|
#indice = ip.find('.')
|
||
|
#msb = ip[:indice]
|
||
|
#ip = ip.replace(msb, 'x' * len(msb))
|
||
|
|
||
|
print("IP interna:", gethostbyname(gethostname()))
|
||
|
print("IP externa:", ip)
|