Initial import of anticapum. - 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 8592f71cf80b2ff69f646dfe36ccf87f9c2ae3ed
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Mon, 1 Jan 2018 01:00:00
Initial import of anticapum.
Diffstat:
anticapum.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r 8592f71cf80b anticapum.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/anticapum.py Mon Jan 01 01:00:00 2018 +0100
@@ -0,0 +1,45 @@
+#!/usr/pkg/bin/python3.6
+
+import getpass
+import ssl
+from netrc import netrc
+from urllib import parse, request
+
+
+ANTICAPUM_URI = 'https://captive.dii.univpm.it/login.php'
+ANTICAPUM_NETRC_MACHINE = 'captive.univpm.it'
+ANTICAPUM_SLEEP = 310
+
+
+def credential():
+ """Return username and password tuple using .netrc file or prompting the
+ user interactively if no netrc entry is present.
+ """
+ try:
+ (username, _, password) = netrc().authenticators(ANTICAPUM_NETRC_MACHINE)
+ except:
+ username = input('username: ')
+ password = getpass.getpass('password: ')
+
+ return username, password
+
+
+def login(username, password):
+ """Login to the captive portal using provided username and password
+ """
+ auth = parse.urlencode({ 'username': username, 'password': password })
+ auth = auth.encode('utf-8')
+ sc = ssl.SSLContext()
+ sc.verify_mode = ssl.CERT_NONE
+ with request.urlopen(ANTICAPUM_URI, data=auth, context=sc) as f:
+ pass
+
+
+if __name__ == '__main__':
+ import time
+
+ username, password = credential()
+
+ while True:
+ login(username, password)
+ time.sleep(ANTICAPUM_SLEEP)