-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path67.py
More file actions
17 lines (12 loc) · 645 Bytes
/
67.py
File metadata and controls
17 lines (12 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Problem 67: Write a program myip.py to print the external IP address of the machine. Use the response
# from http://httpbin.org/get and read the IP address from there. The program should print only the
# IP address and nothing else.
import re
import json
import urllib.request
def getExtIP():
response = urllib.request.urlopen('http://httpbin.org/get') # open json url
jsonstring = response.read().decode('utf-8') # dump json file into string
jsondict = json.loads(jsonstring) # deserialize json string into a dictionary
return jsondict['origin'] # get the value of the external IP from the response
print(getExtIP())