Skip to content

Instantly share code, notes, and snippets.

@ourren
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourren/822f6a1b975aac7e6f92 to your computer and use it in GitHub Desktop.
Save ourren/822f6a1b975aac7e6f92 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding=utf-8
import re
import urllib
import urllib2
from bs4 import BeautifulSoup
url = 'http://routerpasswords.com'
req = urllib2.Request(
url=url)
content = urllib2.urlopen(req).read()
r = re.compile(r'<option value=\"(.*?)\"')
html = r.findall(content)
router_user = list()
router_pw = list()
for i in range(len(html)):
data = urllib.urlencode({
'findpass': 1,
'router': html[i],
'findpassword': 'Finde+Password'
})
req2 = urllib2.Request(
url=url,
data=data)
content2 = urllib2.urlopen(req2).read()
soup = BeautifulSoup(content2)
all = soup.findAll("table")
sp = BeautifulSoup(str(all))
trs = sp.findAll(lambda tag: tag.name == 'td')
length = len(trs)
i = 0
if (i < length):
ret_str = str(trs[i]).replace('<td>', '').replace('</td>', '').replace('<b>', '').replace('</b>', '')
ret_str += '\t' + str(trs[i + 1]).replace('<td>', '').replace('</td>', '')
ret_str += '\t' + str(trs[i + 2]).replace('<td>', '').replace('</td>', '')
user = str(trs[i + 3]).replace('<td>', '').replace('</td>', '')
ret_str += '\t' + user
router_user.append(user)
password = str(trs[i + 4]).replace('<td>', '').replace('</td>', '')
ret_str += '\t' + password
router_pw.append(password)
ret_str += '\n'
i += 5
file_object = open('router.txt', 'a+')
file_object.write(ret_str)
file_object.close()
router_user = list(set(router_user))
router_pw = list(set(router_pw))
hfile = open('route_user.txt', 'a+')
hfile.write('\n'.join(router_user))
hfile.close()
hfile = open('route_pw.txt', 'a+')
hfile.write('\n'.join(router_pw))
hfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment