Created
December 24, 2019 10:05
-
-
Save Evilcry/9917cb9abdebd3032602c52c7070f85a to your computer and use it in GitHub Desktop.
Downloads the full IP range per country
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"} | |
r = requests.get("https://lite.ip2location.com/...your-country...-ip-address-ranges", headers = headers) | |
txt = r.text | |
f = open("_ranges.txt","w") | |
soup = BeautifulSoup(txt,"lxml") | |
tbody = soup.find("tbody") | |
rows = tbody.find_all("tr") | |
for row in rows: | |
cols = row.find_all("td") | |
start = cols[0].text | |
stop = cols[1].text | |
iplen = int(cols[2].text.replace(",","")) | |
if iplen >= 128: | |
print start, stop, iplen | |
f.write(start + "-" + stop + "\n") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment