User:Pedro Sá Couto/Prototyping 5th/IPdetails: Difference between revisions
(Created page with "<source lang="python"> <source/>") |
No edit summary |
||
Line 1: | Line 1: | ||
<source lang="python"> | <source lang="python"> | ||
<source | import re | ||
import json | |||
from urllib.request import urlopen | |||
url = 'http://ipinfo.io/json' | |||
response = urlopen(url) | |||
data = json.load(response) | |||
IP=data['ip'] | |||
org=data['org'] | |||
city = data['city'] | |||
country=data['country'] | |||
region=data['region'] | |||
print ('IP information – \n ') | |||
print('IP: ' + IP + '\n' + 'Region: ' + region + '\n' + 'Country: ' + country + '\n' + 'City: ' + region) | |||
</source> |
Revision as of 16:26, 8 January 2020
import re
import json
from urllib.request import urlopen
url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)
IP=data['ip']
org=data['org']
city = data['city']
country=data['country']
region=data['region']
print ('IP information – \n ')
print('IP: ' + IP + '\n' + 'Region: ' + region + '\n' + 'Country: ' + country + '\n' + 'City: ' + region)