commit d171187ebf031f266162eb0d3a451dfefd3e7dd7 Author: Yoander Valdés Rodríguez Date: Sat Mar 2 18:27:27 2024 -0500 first commit diff --git a/findip.py b/findip.py new file mode 100644 index 0000000..98c4faf --- /dev/null +++ b/findip.py @@ -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)