-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindIP.py
More file actions
34 lines (29 loc) · 985 Bytes
/
findIP.py
File metadata and controls
34 lines (29 loc) · 985 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
26
27
28
29
30
31
32
33
34
import requests as req
import re
import sys
def main():
for i in range(1, len(sys.argv)):
country = sys.argv[i]
s = req.session()
res = s.get("https://lite.ip2location.com/" + country + "-ip-address-ranges")
i = 0
result = ""
for line in res.text.splitlines():
a = re.search(r'<td>(.*)</td>', line, re.M|re.I)
if a:
ip = a.group().replace("<td>","").replace("</td>","")
if i % 2 == 0:
result += ip
else:
result += "," + ip + "\n"
i += 1
print(ip)
file = open(country, "w")
file.write(result)
file.close()
if len(sys.argv) == 1:
print("Usage : python3 findIP.py COUNTRY_LIST")
print("Example: python3 findIP.py france united-kingdom united-states germany")
print("For viewing list of countries visit: https://lite.ip2location.com ")
else:
main()