Created
April 5, 2017 01:04
-
-
Save taojy123/ac1927d25f0c79165f42f0570abf59bd to your computer and use it in GitHub Desktop.
TP-Link 路由器自动重选桥接信道并重启
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=utf8 | |
import cookielib | |
import urllib2, urllib | |
import time | |
import re | |
import traceback | |
import time | |
for i in [10] + range(10, 30) + range(100, 120) + range(2, 10) + range(30, 256): | |
host = 'http://192.168.1.%d' % i | |
print host | |
try: | |
r = urllib2.urlopen(host, timeout=2).read() | |
except Exception as e: | |
r = '' | |
print e | |
if 'TL-WR800N' in r: | |
print 'find host!' | |
break | |
cj = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
opener.addheaders = [ | |
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'), | |
# ('Accept-Encoding', 'gzip, deflate, sdch'), | |
('Accept-Language', 'zh-CN,zh;q=0.8,zh-TW;q=0.6,en;q=0.4,fr;q=0.2,ja;q=0.2'), | |
('Connection', 'keep-alive'), | |
('Cookie', 'tLargeScreenP=1; subType=pcSub; tPlatform=1; TPLoginTimes=0; Authorization=Basic%20YWRtaW46MDk4NzY1NDMyMQ%3D%3D'), | |
('Host', '%s' % host), | |
('Referer', '%s/userRpm/WlanNetworkRpm.htm' % host), | |
('Upgrade-Insecure-Requests', '1'), | |
('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'), | |
] | |
def get_page(url, data=None): | |
resp = None | |
n = 0 | |
while n < 3: | |
n = n + 1 | |
try: | |
resp = opener.open(url, data, timeout=5) | |
page = resp.read() | |
return page | |
except: | |
#traceback.print_exc() | |
time.sleep(2) | |
print "Try after 2 seconds ..." | |
continue | |
raise Exception("Get page failed") | |
# formData = urllib.urlencode({'username' : "abc", | |
# 'password' : "123", | |
# }) | |
# p = get_page(url, formData) | |
# print p | |
url = '%s/userRpm/popupSiteSurveyRpm.htm?select=true&wrr=true&sb=true&ssid=TP-LINK_75BA8E&curRegion=0&channel=1&chanWidth=2&mode=5&addr_type=1' % host | |
print url | |
p = get_page(url) | |
p = p.replace('\r', '').replace('\n', '') | |
channel = re.findall(r'"ChinaNet-pWHL",\d+?,(\d+?),', p)[0] | |
print channel | |
url = '%s/userRpm/WlanNetworkRpm.htm?ssid1=TP-LINK_75BA8E&wlMode=2&channel=%s&mode=5&chanWidth=2&ap=1&broadcast=2&wdsbrl=2&brlssid=ChinaNet-pWHL&brlbssid=D4-AD-2D-01-29-31&detctwds=1&keytype=4&wepindex=1&keytext=vjlzak5w&Save=1' % (host, channel) | |
print url | |
p = get_page(url) | |
url = 'http://host/userRpm/SysRebootRpm.htm?Reboot=' | |
url = '%s/userRpm/SysRebootRpm.htm?Reboot=1' % host | |
print url | |
p = get_page(url) | |
if 'TL-WR800N' in p: | |
print 'success!' | |
print 'end' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment