first commit

This commit is contained in:
Yoander Valdés Rodríguez 2024-03-02 18:27:27 -05:00
commit d171187ebf

22
findip.py Normal file
View file

@ -0,0 +1,22 @@
#!/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)