first commit
This commit is contained in:
commit
d171187ebf
1 changed files with 22 additions and 0 deletions
22
findip.py
Normal file
22
findip.py
Normal 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)
|
Loading…
Reference in a new issue