acasown/bong/__init__.py
2018-11-09 00:30:20 +01:00

43 lines
949 B
Python

import requests
import xml.etree.ElementTree as ET
class Bing:
def __init__(self):
self.url = 'https://www.bing.com/search'
self.hosts = []
def search_hosts(self, hosts):
for host in hosts:
self.search(host['ip'], 1)
return self.hosts
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)
#print({'ip': ip, 'vhosts': vhosts, 'urls': urls})
self.hosts.append({'ip': ip, 'vhosts': vhosts, 'urls': urls})
def parse(self, tree):
urls = []
vhosts = []
count = 0
for i in tree[0]:
if i.tag == 'item':
count += 1
url = i[1].text
if url not in urls:
urls.append(url)
return urls