User:Pedro Sá Couto/Prototyping 5th/IPdetails: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
=IP discrimination= | |||
==Output== | ==Output== | ||
IP information – | IP information –<br> | ||
<br> | |||
IP: 145.24.131.42 | IP: 145.24.131.42<br> | ||
Region: South Holland | Region: South Holland<br> | ||
Country: NL | Country: NL<br> | ||
City: South Holland | City: South Holland<br> | ||
<source lang="python"> | <source lang="python"> |
Latest revision as of 16:28, 8 January 2020
IP discrimination
Output
IP information –
IP: 145.24.131.42
Region: South Holland
Country: NL
City: South Holland
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)