__init__.py 949 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import requests
  2. import xml.etree.ElementTree as ET
  3. class Bing:
  4. def __init__(self):
  5. self.url = 'https://www.bing.com/search'
  6. self.hosts = []
  7. def search_hosts(self, hosts):
  8. for host in hosts:
  9. self.search(host['ip'], 1)
  10. return self.hosts
  11. def search(self, ip, first):
  12. for first in range(1, 200, 10):
  13. urls = []
  14. vhosts = []
  15. r = requests.get(self.url, params={'q': 'ip:' + ip, 'format': 'rss', 'first': first})
  16. tree = ET.fromstring(r.content)
  17. urls = self.parse(tree)
  18. if len(urls) < 10:
  19. break
  20. for u in urls:
  21. vhost = u.rsplit('/')[2]
  22. if vhost not in vhosts:
  23. vhosts.append(vhost)
  24. #print({'ip': ip, 'vhosts': vhosts, 'urls': urls})
  25. self.hosts.append({'ip': ip, 'vhosts': vhosts, 'urls': urls})
  26. def parse(self, tree):
  27. urls = []
  28. vhosts = []
  29. count = 0
  30. for i in tree[0]:
  31. if i.tag == 'item':
  32. count += 1
  33. url = i[1].text
  34. if url not in urls:
  35. urls.append(url)
  36. return urls