Add a CaptiveResponeParser to parse the form containing data used to renew/logo… - anticapum - Handle Università Politecnica delle Marche captive portal
(HTM) hg clone https://bitbucket.org/iamleot/anticapum
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset c10ce3199d0825a9896c00f0aac8bc4020175de2
(DIR) parent 9e3c70a6877f0599f55189838e11b0614551c4d7
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Thu, 11 Jan 2018 22:57:42
Add a CaptiveResponeParser to parse the form containing data used to renew/logout
Add a parser for the response of login(). This will parse username, ip,
timestamp, sid and pulsante elements that are passed to renew connection and for
to logout.
Diffstat:
anticapum.py | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff -r 9e3c70a6877f -r c10ce3199d08 anticapum.py
--- a/anticapum.py Thu Jan 11 21:31:50 2018 +0100
+++ b/anticapum.py Thu Jan 11 22:57:42 2018 +0100
@@ -31,6 +31,7 @@
import getpass
import ssl
from netrc import netrc
+from html.parser import HTMLParser
from urllib import parse, request
@@ -42,6 +43,24 @@
ANTICAPUM_SLEEP = 310
+class CaptiveResponseParser(HTMLParser):
+ """Parse the <form> that contains the username, ip, timestamp, sid and
+ pulsante attributes used to renew connections."""
+ def handle_starttag(self, tag, attrs):
+ a = dict(attrs)
+ if 'id' in a:
+ if a['id'] == 'username':
+ self.username = a.get('value')
+ elif a['id'] == 'ip':
+ self.ip = a.get('value')
+ elif a['id'] == 'timestamp':
+ self.timestamp = a.get('value')
+ elif a['id'] == 'sid':
+ self.sid = a.get('value')
+ elif a['id'] == 'pulsante':
+ self.pulsante = a.get('value')
+
+
def credential():
"""Return username and password tuple using .netrc file or prompting the
user interactively if no netrc entry is present.