Created
December 20, 2014 09:59
-
-
Save coffeewasmyidea/9ed4e57039736cb41724 to your computer and use it in GitHub Desktop.
Getting current status (ISP netorn.ru)
This file contains 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
#!/usr/bin/env python | |
# coding=utf-8 | |
import os, mechanize, cookielib, re | |
CURRENT_DIR = os.path.dirname(__file__) | |
br = mechanize.Browser() | |
cj = cookielib.LWPCookieJar() | |
br.set_cookiejar(cj) | |
br.set_handle_equiv(True) | |
br.set_handle_gzip(False) | |
br.set_handle_redirect(True) | |
br.set_handle_referer(True) | |
br.set_handle_robots(False) | |
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) | |
br.addheaders = [('User-agent', 'Mozilla/5.0')] | |
br.open("https://userstat.netorn.ru/noaccess.php?ERROR_PWD9") | |
br.select_form(nr=0) | |
br["Login"] = "YOURHOST" | |
br["Password"] = "YOURPASS" | |
br.submit(name='Submit') | |
results = br.response().read() | |
f = open(os.path.join(CURRENT_DIR, './ses.html'), 'w') | |
f.write(results) | |
f.close() | |
regex = re.compile('Session=(.*)"') | |
with open(os.path.join(CURRENT_DIR, './ses.html')) as file: | |
for line in file.readlines(): | |
if "Session" in line: | |
src = regex.findall(line) | |
ses = ''.join(src) | |
try: | |
ses | |
except NameError: | |
raise Exception('pawword error') | |
br.open("https://userstat.netorn.ru/index.php?Session=" + ses) | |
statistics = br.response().read() | |
f2 = open(os.path.join(CURRENT_DIR, './result.html'), 'w') | |
f2.write(statistics) | |
f2.close() | |
with open(os.path.join(CURRENT_DIR, './result.html')) as file: | |
f3 = open(os.path.join(CURRENT_DIR, './parse.html'), 'w') | |
for line in file.readlines(): | |
if "width='250'" in line: | |
line.strip() | |
f3.write(line) | |
f3.close() | |
f3 = open(os.path.join(CURRENT_DIR, "./parse.html")) | |
line = f3.readlines() | |
if "green" in line[2]: | |
status = "enable" | |
else: | |
status = "disable" | |
balance = re.search("[0-9.]+", line[3][34:45]).group() | |
credit = re.search("[0-9.]+", line[4][34:45]).group() | |
# traffic = re.search("[0-9.]+", line[5][34:50]).group() | |
# overage = re.search("[0-9.]+", line[6][34:50]).group() | |
daysleft = re.search("[0-9.]+", line[9][34:40]).group() | |
try: | |
os.remove(os.path.join(CURRENT_DIR, "./ses.html")) | |
except: | |
pass | |
try: | |
os.remove(os.path.join(CURRENT_DIR, "./result.html")) | |
except: | |
pass | |
try: | |
os.remove(os.path.join(CURRENT_DIR, "./parse.html")) | |
except: | |
pass | |
print "========================================" | |
print "STATUS: %s" % status | |
print "BALANCE: %s rub" % balance | |
print "" | |
print "CREDIT: %s" % credit | |
# print "TRAFFIC: %s Mb" % traffic | |
# print "OVERAGE: %s Mb" % overage | |
print "DAYS LEFT: %s" % daysleft | |
print "========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment