Created
August 1, 2014 20:46
-
-
Save bijanebrahimi/14cfd1f8b98baec18c24 to your computer and use it in GitHub Desktop.
نمایش باقیمانده ترافیک مشترکان ADSL مخابرات
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
#!/usr/bin/env python2.7 | |
# Author: Bijan EBrahimi [[email protected]] | |
# License: GPL 3 or later | |
# Published: Sat Aug 2 01:11:11 IRDT 2014 | |
# | |
# Python Script to Bypass Captcha at Login page of TCI ADSL Provider | |
# to show remaining bandwidth. | |
# With Special thanks to @shabgard | |
# | |
# Dependencies: | |
# sudo pip install pyquery | |
# | |
# Note: Please Remember to fill your username and password below | |
# | |
import re | |
import urllib | |
import urllib2 | |
from cookielib import CookieJar | |
from pyquery import PyQuery as pq | |
# Your Username and Password | |
username = '511*******' | |
password = '**********' | |
# Set CookieJar to handle Session Cookie | |
cj = CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
# Login URL | |
url = "http://2020.tci-khorasan.ir/Pages/Login.aspx" | |
# Fetch Login HTML Code | |
response = opener.open(url) | |
login_html = response.read() | |
# Create Some Kinda DOM Object Using PyQuery | |
dom = pq(login_html) | |
# Get Form Hidden Fields | |
viewstate = dom("#__VIEWSTATE").val() | |
eventvalidation = dom('#__EVENTVALIDATION').val() | |
# Captcha idiotically is stored in VIEWSTATE in base64 encoded form | |
viewstate_decoded = viewstate.decode("base64") | |
# Retrieve Captcha from VIEWSTATE decoded text | |
captcha = re.search("Captcha2text.{2}(.{6})", viewstate_decoded).groups()[0] | |
# Form Data we should send | |
form = {'ctl00$mpch$txtUserName': username, | |
'ctl00$mpch$txtPassword': password, | |
'ctl00$mpch$MyCaptcha2$TxtCpatcha': captcha, | |
'ctl00$mpch$btnLogin': u'\u0648\u0631\u0648\u062f'.encode('utf8'), | |
'ctl00$mpch$txtADSLNumber': '', | |
'__VIEWSTATE': viewstate, | |
'__EVENTVALIDATION': eventvalidation, | |
'__EVENTTARGET': '', | |
'__EVENTARGUMENT': ''} | |
data = urllib.urlencode(form) | |
# Send the Login Request | |
response = opener.open(url, data) | |
the_page = response.read() | |
# Create Some Kinda DOM Object Using PyQuery on Response | |
dom = pq(the_page) | |
# Show Element Contaning Remaining Bandwidth | |
print dom('#ctl00_mpch_uca_lblServiceTraffic').text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment