Skip to content

Instantly share code, notes, and snippets.

@VMuliadi
Last active June 29, 2017 09:22
Show Gist options
  • Save VMuliadi/211bb1c388ea94c6ff6a7b10e1d239af to your computer and use it in GitHub Desktop.
Save VMuliadi/211bb1c388ea94c6ff6a7b10e1d239af to your computer and use it in GitHub Desktop.
Command Line version to logged in/out into Sanata Dharma University internet access
import requests, sys, getpass, urllib2
from bs4 import BeautifulSoup
from lxml import html
username = sys.argv[1]
base_url = 'http://logout.usd/login'
result = requests.request('GET', base_url)
if str(result.status_code) == '200': # check connectivity
password = getpass.getpass('Password for %s : ' % username)
logging_in = requests.post(base_url, data={'username': username, 'password': password})
html_tags = html.fromstring(logging_in.content)
try : # display an error page from MikroTik Captive Portal page to the user
print html_tags.xpath('//div[@style="color: #FF8080; font-size: 9px"]/text()')[0]
except IndexError :
status_page = 'http://logout.usd/status'
page = urllib2.urlopen(status_page)
soup = BeautifulSoup(page, 'lxml')
ip_address = soup.findAll('span',{'class':'style4'})[1].get_text()
print 'Anda berhasil login dengan IP %s' % str(ip_address)
import requests
base_url = 'http://logout.usd/logout' # base url to logged out
result = requests.request('GET', base_url) # establish a connection
if str(result.status_code) == '200' :
if 'password' in str(result.text) : print 'Anda belum login'
else : print 'Anda berhasil logout'
@VMuliadi
Copy link
Author

VMuliadi commented Mar 16, 2017

How to Use?

For login.py > python login.py '<NIM> '
Example : python login.py '135314003'

For logout.py > 'python logout.py' (without argument)
Mention me on this comment to report a bug

Basically this script works with all network as long the host (base_url) pointing right into the Captive Portal (in MikroTik). I created this script based on MikroTik Default Captive Portal. Feel free to replace the base_url with your own

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment