forked from ip2location/IP2Location-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlookup.py
More file actions
25 lines (19 loc) · 626 Bytes
/
Copy pathlookup.py
File metadata and controls
25 lines (19 loc) · 626 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os, IP2Location, sys, ipaddress
# database = IP2Location.IP2Location(os.path.join("data", "IPV6-COUNTRY.BIN"), "SHARED_MEMORY")
database = IP2Location.IP2Location(os.path.join("data", "IPV6-COUNTRY.BIN"))
try:
ip = sys.argv[1]
if ip == '' :
print ('You cannot enter an empty IP address.')
sys.exit(1)
else:
try:
ipaddress.ip_address(ip)
except ValueError:
print ('Invalid IP address')
sys.exit(1)
rec = database.get_all(ip)
print (rec)
except IndexError:
print ("Please enter an IP address to continue.")
database.close()