MyIP/findip.py
Yoander Valdés Rodríguez d171187ebf first commit
2024-03-02 18:29:28 -05:00

22 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)