Python: Automated login to local hot spot

27/06/2018

BTWifi-page

I’ve been using a BTWifi-with-FON hot spot for internet access.  The way it works is: user clicks on connect in wifi manager, then browses to https://www.btopenzone.com:8443/home, fills in the form with User email address and Password.  This lets the user access the internet for anything between 1 and 3 hours, depending on time of day and day of week.  Then access runs out and the user must sign in again.

If you’re using the hotspot for an extended period of time, having to go through this palaver can be pretty irritating.  Luckily I’ve started learning python, which is an excellent language for automating this kind of procedure.  So this is the script I have written to make my use of the hot spot a little less stressful:

import pymsgbox
import requests
import time
import sys

def log_in():

    url = “https://www.btopenzone.com:8443/tbbLogon”
    values = {“username”: “foo@bar.com”,
    “password”: “foobar”}
    requests.post(url, data=values)

def vpn_check():
    p = requests.get(“http://www.icanhazip.com/”)
    ip = p.text.rstrip()
    if ip == “!!!.!!!.!!!.!!!”:
        # uncomment line below for vpn connection confirmation
        #pymsgbox.native.alert(“Logged into VPN”, t)
        sys.exit(0)

test_url = ‘https://www.btopenzone.com:8443/home’
response = requests.get(test_url)
html = response.content

page_start = str(html[0:1000])

t = time.strftime(“%X”)

if “DANTE” not in page_start:
    vpn_check()
    pymsgbox.native.alert(“Signed OUT, click me to sort it”, t)
    log_in()
    #uncomment following lines for signed-in confirmation
#else:
    #pymsgbox.native.alert(“Signed in”, t)

At the top of the script I import the modules I need. Pymsgbox provides pop-up message functionality. Requests handles the webpage parsing and filling in the online form.  Time enables the script to display the time in the pop-up boxes. And it uses sys so it can drop out of the vpn_check() function.

Next up, it defines the log_in() function.  Although the user navigates to https://www.btopenzone.com:8443/home to sign in, the form url is http://www.btopenzone.com:8443/tbbLogon.  The values to be provided are username (the user’s email address) and password (a password).  According to the ancient custom, here I have used foo@bar.com as user’s email address, and the password is foobarRequests delivers these values to the form url.

The script goes on to define the vpn_check() function. As this is a public wifi hotspot I use a vpn service, Invisible Browsing VPN aka ibVPN.  The vpn_check() function checks whether the computer is using a vpn by comparing the public ip address to that used by the vpn service.  Here the vpn ip address is represented by X.X.X.X.  If the ip address is the same as the vpn’s address, the script terminates.

Now the script proper starts.  It checks whether we are already signed in to the BTWifi service.  This is performed by going to a particular url – https://www.btopenzone.com:8443/home and examining the html source code.  If the computer is already signed in, that webpage will redirecte us to http://home.bt.com/bt-wifi-01364197228851.  The first thousand characters of that page’s html source code contains the string “DANTE”.  If the string is present, we know we are signed in and the script terminates.  If the string is not present, the computer is either using a vpn or is not signed in to BTWifi.

 

So the script performs the vpn_check(), using the online service at http://www.icanhazip.com to check the computer’s public ip address.  If this matches the vpn ip address, X.X.X.X we know the computer is signed into BTWifi and using the vpn.  If the public ip address does not match the vpn ip address, we deduce that we are not using the vpn and therefore we are not signed in.  So a pop-up message tells the user that we are not signed in, and if the user wants to sign in he should click the OK button.  If he clicks the button, the script goes on to the log_in() function, to sign in to BTWifi.

With log_in() the script navigates to the sign-in form at https://www.btopenzone.com:8443/TBBLogon, and fills in the form fields with the values.  We are signed in, and the script terminates.

On my computers, which use either Windows 7 or Windows 8.1 operating systems, I have scheduled this script to run every 5 minutes.  It regularly checks the computer’s signed-in status, putting up a message if the computer is no longer signed in. The message box says : “Signed OUT, click me to sort it.” Click the button and the script signs into the wifi.  This is much less stressful than having the palaver of going to the wifi sign-in page and dealing with the form.

This script is very much a work in progress.  Look at the code and you will see a number of lines commented out.  Uncommented, these lines of code provide confirmation when the script finds out it is signed into the wifi or using the vpn.  These were used for testing.  I intend to comment out the message that we are not signed in, and have the script deal with it in the background.  This will allow me to work online or watch a streaming video without interruption – unless a connection problem arises!

I have found that sometimes there is a connection error, python raises an exception and program exception is interrupted. If I’m running the script in IDLE the exception output is printed in the interactive shell, but if it is working in the background, scheduled to run every 5 minutes I won’t get any error info.  I am going to see if a try/except block will deal with it. I plan to have basic error info printed in a pymsgbox pop-up.  I can then investigate what’s up with the connection, whether the problem is with the hot-spot or my own hardware. Sometimes when I’m experiencing connection problems, I run diagnostics on network connection and Windows resets my network adapter and that fixes the problem!

If anyone has any suggestions about this script please let us know in Comments.  Constructive criticism is welcome.  If anyone else finds this helpful (perhaps you also use a BTWifi-with-FON hot spot?), let us know!  And maybe buy me a coffee…?  🙂

Buy Me A Coffee


“Guerilla Open Access Manifesto” by Aaron Swartz

29/07/2017

Aaron_Swartz_profile

Aaron Swartz was a computer programmer, writer, political organiser, hacker, and hacktivist of note.  Amongst other accomplishments he founded Watchdog.net, “the good government site with teeth,” to aggregate and visualize data about politicians, was a co-founder of the Progressive Change Campaign Committee and Demand Progress; with Virgil Griffith he worked on Tor2web, an early (2008) HTTP proxy for Tor-hidden services and with Kevin Poulsen he created Dead Drop (now known as “Secure Drop”), a mechanism allowing whistleblowers to send files to the media anonymously.  He was prosecuted for making the data in JSTOR, a digital repository of academic journal articles, available to users for free.  He refused a plea bargain that would have seen him serve 6 months in a low-security prison, preferring to make the authorities justify the prosecution.  He faced a possible 50 years of imprisonment and $1 million in fines, for pursuing the hacker belief that all information wants to be free.  Swartz committed suicide on January 11, 2013. After his death, federal prosecutors dropped the charges. [Thanks to Wikipedia.org for the above.]  He was a champion for freedom, in the best hacker tradition, and nine years ago he wrote the following manifesto.

Guerilla Open Access Manifesto

Information is power. But like all power, there are those who want to keep it for
themselves. The world’s entire scientific and cultural heritage, published over centuries
in books and journals, is increasingly being digitized and locked up by a handful of
private corporations. Want to read the papers featuring the most famous results of the
sciences? You’ll need to send enormous amounts to publishers like Reed Elsevier.

There are those struggling to change this. The Open Access Movement has fought
valiantly to ensure that scientists do not sign their copyrights away but instead ensure
their work is published on the Internet, under terms that allow anyone to access it. But
even under the best scenarios, their work will only apply to things published in the future.
Everything up until now will have been lost.

That is too high a price to pay. Forcing academics to pay money to read the work of their
colleagues? Scanning entire libraries but only allowing the folks at Google to read them?
Providing scientific articles to those at elite universities in the First World, but not to
children in the Global South? It’s outrageous and unacceptable.

“I agree,” many say, “but what can we do? The companies hold the copyrights, they
make enormous amounts of money by charging for access, and it’s perfectly legal —
there’s nothing we can do to stop them.” But there is something we can, something that’s
already being done: we can fight back.

Those with access to these resources — students, librarians, scientists — you have been
given a privilege. You get to feed at this banquet of knowledge while the rest of the world
is locked out. But you need not — indeed, morally, you cannot — keep this privilege for
yourselves. You have a duty to share it with the world. And you have: trading passwords
with colleagues, filling download requests for friends.

 

Meanwhile, those who have been locked out are not standing idly by. You have been
sneaking through holes and climbing over fences, liberating the information locked up by
the publishers and sharing them with your friends.

But all of this action goes on in the dark, hidden underground. It’s called stealing or
piracy, as if sharing a wealth of knowledge were the moral equivalent of plundering a
ship and murdering its crew. But sharing isn’t immoral — it’s a moral imperative. Only
those blinded by greed would refuse to let a friend make a copy.

Large corporations, of course, are blinded by greed. The laws under which they operate
require it — their shareholders would revolt at anything less. And the politicians they
have bought off back them, passing laws giving them the exclusive power to decide who
can make copies.

There is no justice in following unjust laws. It’s time to come into the light and, in the
grand tradition of civil disobedience, declare our opposition to this private theft of public
culture.

We need to take information, wherever it is stored, make our copies and share them with
the world. We need to take stuff that’s out of copyright and add it to the archive. We need
to buy secret databases and put them on the Web. We need to download scientific
journals and upload them to file sharing networks. We need to fight for Guerilla Open
Access.

With enough of us, around the world, we’ll not just send a strong message opposing the
privatization of knowledge — we’ll make it a thing of the past. Will you join us?

Aaron Swartz

July 2008, Eremo, Italy

bmc-orange


“Killer robots should be banned…” But I want one!

20/11/2012

Image

The Terminator – coming to a war zone near you!

 Human Rights Watch has released a 50-page report on the subject of “fully autonomous weapons” that could kill without any human interaction required – in other words, killer robots, like Arnie in The Terminator.  And surprise surprise, the report (catchily entitled Losing Humanity: the Case Against Killer Robots) says that they should be banned – now, before anyone pours too much money into such a project.

“Giving machines the power to decide who lives and dies on the battlefield would take technology too far,” said Steve Goose, the HRW arms division director. “Human control of robotic warfare is essential to minimising civilian deaths and injuries.”  The robot would have to make ethical judgements as well as tactical and strategic decisions: for instance, are some civilian casualties acceptable weighed against the battle outcome.  At the moment these kind of decisions are made by human officers on the battle ground.  But can a computer be fully capable?

And then there’s the scenario of a malfunctioning robot soldier.  Do we really want to risk having a heavily armed killer robot running amok?

There are already basic semi-automous weapons systems already in use – for instance the drone aircraft that are famous for firing hellfire missiles at innocent Afghan wedding parties, and the Phalanx CIWS (Close-In Weapons System) that is used to protect ships from missiles. And in December 2010, the South Korean firm DoDAAM unveiled the Super aEgis II  an automated turret-based weapon platform that uses thermal imaging to lock onto human-sized targets up to 3km away. It is able to function during nighttime and regardless of weather conditions . No one has yet created a robot soldier, but several countries are actively looking into the subject, such as the US, China, Germany, Israel, South Korea, Russia and Britain.  The HRW report claims that experts believe operative machines could be ready in 20 years if not sooner.  And who knows what is going on in top secret defence projects?  They’re not called “top secret” for nothing.

So the report recommends that international treaties banning these kinds of weapons should be banned now, before any country gets too involved in such a project – no government wants to scrap a project that it’s already invested billions of dollars into.

“It is essential to stop the development of killer robots before they show up in national arsenals,” Steve Goose said. “As countries become more invested in this technology, it will become harder to persuade them to give it up.”

But it’s hard to see this idea stay unexplored.  Automation is invading everyday life – why shouldn’t it be used on the battlefield?  I can certainly imagine the robot soldier being sold to the public as a way to avoid seeing our boys coming home in body bags.  But what will it be like for the people who are on the front line: not just soldiers, but the people who actually live in the war zone?  Mistakes are made by human soldiers – what could a fritzed Terminator be capable of?

Locations of visitors to this page


free web stat


How to search the internet 5: advanced operators

13/05/2010

This is part 5 of my guide to searching the internet. Here are links to:

Part 1: History of internet search;
Part 2: How a modern web search site works;
Part 3: How to actually use a modern search engine
Part 4: How to understand the results you get from using a modern web search

I covered basic use of operators in part 3. But the proper use of operators is very important if you want to get the most from a search engine, especially if the search is at all complicated. So I’m going to go into more detail on the subject here. I got much of the info from other sites, especially www.GoogleGuide.com. But I (rather modestly) think that i present the info in a much more readable and usable form.

Okay, here we go. Operators are special uses of certain words or combination of words that mean more to the search engine than the plain use of words as simple search terms. Here’s a quick example, which you may find familiar if you’ve ever learned how to use Google to find mp3 files: Let’s imagine we want to find mp3 files of tracks by the excellent early British punk band The Clash. What we actually find are listings of the contents of directories that contain the mp3 music files. So, we could use Google search terms like this:

intitle:index.of mp3 “the clash” -.html -.htm

Let’s examine that bit by bit. It starts with intitle:index.of. The intitle part tells Google to look in the title of a page for a particular word or phrase. In this instance, the phrase to look for is index.of (which would, incidentally, look for titles that include the string “index.of” and “index of” (ie with a space rather than a period). That’s how Google and most (all?) other modern search engines work. The reason for looking for a page whose title includes the phrase “index of” is that a web page listing the contents of a directory will very likely have a title containing those words. It’s also looking for the word mp3 and the phrase “the clash”. You’ll notice we used quotation marks around “the clash”. This is my personal preference: the band was called The Clash, so I want results that contain that band name. Some people disagree, thinking that cuts out a lot of relevant results. And it’s true that some webmasters may have used the word “clash” in the page title. But I think using the word “clash” would pull up lots of irrelevant results like “Clash of the Titans” and “clash of two cultures”. So I stick with the phrase “the clash”. Whether you go with my suggestion or not is up to you.

The last 2 operators in this search are -html and -htm. You see, we’re looking for a page that lists the contents of a directory. This is not a page that is destined to be viewed by site users – it has more of a “housekeeping” function. And as it isn’t meant to be viewed by general users, it is very unlikely to contain mark-up. We’re not looking for marked-up pages; so we don’t want pages whose titles are suffixed .htm or .html. That operator means the same as the NOT operator.

So, that was just a quick example of how operators are used to help construct a search term. Now let’s have a look at what operators are available to a search engine user:

city1 city2: this will look for info on flights from city 1 to city 2. We don’t use the actual names of the city though, we use the 3-letter airport codes. For instance, the search sfo bos will pull up times and info on flights from San Fransisco; whereas the search san fransisco boston pulls up some flight info but also a lot of unrelated results. You can find the 3-letter codes for airports worldwide here.

Here’s some more stuff about advanced Google search operators (with thanks to GoogleGuide.com):

allinanchor:
If you begin your query with allinanchor: Google restricts results to pages containing all query terms you specify in the anchor text on links to the page. Example: the query allinanchor: best museums birmingham will return only pages in which the anchor text on links to the pages contain the words best, museums and birmingham.

Anchor text is the text on a page that is linked to another web page or a different place on the current page. When you click on anchor text, you will be taken to the page or place on the page to which it is linked. When using allinanchor: in your query, do not include any other search operators. The functionality of allinanchor: is also available through the Advanced Web Search page, under Occurrences.

allintext:
If you start your query with allintext:
Google restricts results to those containing all the query terms you specify in the text of the page. For example, allintext: travel packing list will return only pages in which the words “travel”, “packing” and “list” appear in the test of the page. This functionality can also be obtained through the Advanced Web Search Page, under Occurrences.


HAR2009 presentation videos available online

10/11/2009

HAR2009-logo
If, like me, you were caught out by the sudden rush on tickets for HAR2009 and so couldn’t attend the Dutch hackerfest this summer, you may be sighing and distraught that you couldn’t participate in this coming together of Europe’s finest hackerish minds.

Well, nothing can change that. But you can still enjoy many of the talks and presentations through the medium of video. There’s a whole bunch of videos of talks and the like available for download here. Check ’em out, peeps! You might be in danger of actually learning something!!!

There’s also a movie of the event: HAR2009 Impressions by Rick Deckardt. You can download it here. I haven’t watched it yet – I only found out about it a few minutes ago, while checking out the HAR2009 wiki prior to writing this post – but believe me, I shall watch it very soon. These Dutch hacker camps happen just once every 4 years, like leap years or Olympics, so I want to wring every last drop of enjoyment out of this last one. I couldn’t go – boo hoo! – but at least I can pretend!! 😉


%d bloggers like this: