Stufo ed arcistufo di avere una finestra del browser aperta per potermi connettere alla rete WiFi dei NE, ho scritto uno script Python che faccia la stessa cosa.
Ve lo posto sperando vi sia utile. Io lo uso solo sotto Linux, quindi non so se sotto Windows va. In generale dovrebbe, basta avere Python con il supporto per ssl, unicode, urllib2 e re (espressioni regolari).
Sotto Linux basta lanciarlo da shell, sotto Windows dal prompt dei comandi anteponendo il percorso dell'eseguibile python.exe.
Finalmente, ecco lo script...
[code type="markup"]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# WLanConnect: A WLan connection script for the WLan of NE at the University of Rome Tor Vergata.
# Author: Paolo Insogna <shogun713@gmail.com>
# Copyright (C) 2006 Paolo Insogna
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# A copy of the GNU General Public License is available at: http://www.gnu.org/licenses/gpl.txt
#
#PER EVITARE DI INSERIRE NOME UTENTE E PASSWORD AD OGNI ESECUZIONE, SETTARE LE DUE VARIABILI SEGUENTI (NELLA FORMA u'xxx')
USERNAME = u''
PASSWORD = u''
### ---LASCIARE INVARIATO IL RESTO DELLO SCRIPT--- ###
import urllib
import urllib2
import getpass
import sys
import re
regex = re.compile(u'(^(<td align="center"><font size="\+1"><b>
returns = {u'Wrong username or password': u'Nome utente o password errati.', \
u'Missing username or password': u'Nome utente o password mancanti.',\
u'User already exists': u'L\'utente specificato è già loggato.', \
u'User not present': u'Il nome utente è errato o l\'utente non è loggato'\
}
def connect():
try:
#FORMAT DATA
post = urllib.urlencode([(u'username', USERNAME), (u'password', PASSWORD)])
#OPEN THE URL AND GET THE ANSWER
request = urllib2.urlopen(url=u'https://10.0.0.1/login.php', data=post)
lines = request.readlines()
core = lines[16].strip()
#CHECK THE RESULT
match = regex.match(core)
if match != None:
print returns[match.group(u'msg')]
sys.exit(1)
else:
print u'Connessione effettuata con successo.'
sys.exit(0)
except urllib2.URLError, e:
print u'Si è verificato un errore durante la connessione: %s', e
def disconnect():
try:
#FORMAT DATA
post = urllib.urlencode([(u'username', USERNAME), (u'scelta', u'logout')])
#OPEN THE URL AND GET THE ANSWER
request = urllib2.urlopen(url=u'https://10.0.0.1/scelta.php', data=post)
lines = request.readlines()
core = lines[16].strip()
#CHECK THE RESULT
match = regex.match(core)
if match != None:
print returns[match.group(u'msg')]
sys.exit(1)
else:
print u'Disconnessione effettuata con successo.'
sys.exit(0)
except urllib2.URLError, e:
print u'Si è verificato un errore durante la connessione: %s', e
if __name__ == u'__main__':
#CHECK THE FIRST MANDATORY ARGUMENT
if len(sys.argv) < 2 or sys.argv[1] not in (u'on', u'off'):
print u'Utilizzo: %s on|off [username] [password]' % sys.argv[0]
sys.exit(1)
action = sys.argv[1]
#OBTAIN THE OTHER OPTIONAL ARGUMENTS
if len(sys.argv) > 2:
USERNAME = sys.argv[3]
if len(sys.argv) > 3:
PASSWORD = sys.argv[4]
#IF USERNAME OR PASSWORD ARE EMPTY, PROMPT TO THE USER
if USERNAME == u'':
try:
USERNAME = raw_input(u'Inserire il nome utente: ')
except EOFError, e:
print u'Impossibile leggere il nome utente.'
sys.exit(1)
except KeyboardInterrupt, e:
print u'Azione annullata dall\'utente.'
sys.exit(1)
if PASSWORD == u'' and action == 'on':
try:
PASSWORD = getpass.getpass(u'Inserire la password (durante la digitazione non sara\' mostrato nulla): ')
except EOFError, e:
print u'Impossibile leggere la password.'
sys.exit(1)
except KeyboardInterrupt, e:
print u'Azione annullata dall\'utente.'
sys.exit(1)
#FINALLY CONNECT OR DISCONNECT
if action == u'on':
connect()
else:
disconnect()
[/code]
Spero funzioni anche per voi, io l'ho scritto mentre aspettavo la lezione di Cesati...CIAOOOOOOOOOOO!!!
PS: Per evitare di inserire ogni volta nome utente e password, settatele dentro lo script...