acasown/bong/__init__.py

43 lines
949 B
Python
Raw Permalink Normal View History

2018-11-08 15:55:24 +01:00
import requests
import xml.etree.ElementTree as ET
class Bing:
def __init__(self):
self.url = 'https://www.bing.com/search'
2018-11-09 00:30:20 +01:00
self.hosts = []
2018-11-08 15:55:24 +01:00
def search_hosts(self, hosts):
for host in hosts:
2018-11-09 00:30:20 +01:00
self.search(host['ip'], 1)
return self.hosts
2018-11-08 15:55:24 +01:00
2018-11-09 00:30:20 +01:00
def search(self, ip, first):
for first in range(1, 200, 10):
urls = []
vhosts = []
r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first})
tree = ET.fromstring(r.content)
urls = self.parse(tree)
if len(urls) < 10:
break
for u in urls:
vhost = u.rsplit('/')[2]
if vhost not in vhosts:
vhosts.append(vhost)
2018-11-08 15:55:24 +01:00
2018-11-09 00:30:20 +01:00
#print({'ip': ip, 'vhosts': vhosts, 'urls': urls})
self.hosts.append({'ip': ip, 'vhosts': vhosts, 'urls': urls})
2018-11-08 15:55:24 +01:00
def parse(self, tree):
2018-11-09 00:30:20 +01:00
urls = []
vhosts = []
2018-11-08 15:55:24 +01:00
count = 0
for i in tree[0]:
if i.tag == 'item':
count += 1
2018-11-09 00:30:20 +01:00
url = i[1].text
if url not in urls:
urls.append(url)
2018-11-08 15:55:24 +01:00
2018-11-09 00:30:20 +01:00
return urls