Free Hotel Wifi over and over indefinitely with Python and Selenium


In some situations you need to fake / change / spoof a MAC address of your network interface. macchanger Linux command does this job in no time. With this tool you can change your mac address of any Ethernet network device wired or wireless.

Lets say IF the hotel you are at let each device use the internet for a limited amount of time, they must have a way of identifying each device. And a router tells devices apart is by their MAC addresses. Fortunately for us, we can change our MAC address easily.

Lets start with macchanger…

The idea here is randomizing our MAC regularly (every 20 minutes) in order to use the free wifi over and over indefinitely.

There are 3 small commands you need to run. This is needed because macchanger can’t work while your network interface is connected to the router.

# Bring network interface down
ifconfig wlan1 down

# Get random MAC address
macchanger -r wlan1

# Bring the interface back up
ifconfig wlan1 up

In the commands above, wlan1 is the name of my network interface. You can find yours by running ip a. If you run those commands, you can fire up your browser and you will be greeted with the page asking you to pay or try it for 20 minutes. After your time is up, you can run the commands again and keep doing it.

But this is manual labor, and doing it 3 times an hour is too repetitive. Hmm. What’s a good tool to automate repetitive stuff?

Bring in Selenium!

First, lets get those commands out of the way. Using the os module, we can run macchanger from our script.

import os

interface = ‘wlan1′

os.system(f’sudo ifconfig {interface} down’)
os.system(f’sudo macchanger -r {interface}’)
os.system(f’sudo ifconfig {interface} up’)

After these commands our computer should automatically connect to the network as a completely different device. Let’s fire up a browser and try to use the internet.

d = webdriver.Chrome()
d.get(‘http://example.com’)
d.get(‘https://www.somecheaphotel.org/register.php’)

The register.php URL is where I ended up after pressing the Free Wifi link, so the script should open the registration form for us. Let’s fill the form.

In my case, all it asked for was an email address and a full name. If there are more fields, you can fill them in a similar fashion.

num = random.randint(0, 99999)
email = f’test{num}@gmail.com’

d.find_element_by_name(’email’).send_keys(email)
d.find_element_by_name(‘name’).send_keys(‘Bill Gates’)

This should fill the form and press enter to submit it. Afterwards, the portal asked me if I wanted to subscribe to their emails or something like that. Of course, we click Reject without even reading it and close the browser.

d.find_elements_by_class_name(‘reject’)[0].click()
d.close()

After this, you should have an internet connection. You can either run the script whenever you notice your connection is gone, or put it on a cron job / while loop.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.