Skip to content

Instantly share code, notes, and snippets.

@jerinphilip
Created October 1, 2015 13:00
Show Gist options
  • Save jerinphilip/1b192499a3944fc30481 to your computer and use it in GitHub Desktop.
Save jerinphilip/1b192499a3944fc30481 to your computer and use it in GitHub Desktop.
WhatsApp Inc. IP addresses
import lxml.html
import requests
import re, operator
def extract_page_ips(response):
tree = lxml.html.fromstring(response.text)
content = tree.xpath('//div[@id="border-wrapper"]')[0]
expr = re.compile("/ip/[0-9.]*")
hrefs = map(lambda x: x[2], content.iterlinks())
ip_links = filter(expr.match, hrefs)
gsplit = lambda x : x.replace("/ip/", "")
ips = map(gsplit, ip_links)
return list(ips)
def extract_ips(org):
code = requests.codes.ok
page = 0
ips = []
while code == requests.codes.ok:
page = page + 1
link = "https://ipdb.at/org/%s?page=%s"%(org, page)
response = requests.get(link, allow_redirects=False)
code = response.status_code
if (code == requests.codes.ok):
ips = ips + extract_page_ips(response)
return ips
def val(x):
s = list(map(int, x.split('.')))
s.reverse()
t = [ 1000**i for i in range(0, len(s))]
return sum(list(map(operator.mul, t, s)))
ips = extract_ips("WhatsApp_Inc")
sips = sorted(ips, key=val)
with open("ips.txt", "w") as f:
for i in sips:
f.write(i+'\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment