Auto-Connecting with Public Hotspot

by Mar 7, 2014

Many mobile phone service providers offer public hotspots at airports and public places. To connect, you typically need to browse to a logon page, and then manually enter your credentials.

Here is a script that does this automatically. It is tailored to t-mobile.de but in the script, you can see the places that need adjustment for other providers:

function Start-Hotspot
{
  param
  (
    [System.String]
    $Username = 'XYZ@t-mobile.de',
    
    [System.String]
    $Password = 'topsecret'
  )
  
  # change this to match your provider logon page URL
  $url = 'https://hotspot.t-mobile.net/wlan/start.do'

  $r = Invoke-WebRequest -Uri $url -SessionVariable fb   
  
  
  $form = $r.Forms[0]
  
  # change this to match the website form field names:
  $form.Fields['username'] = $Username
  $form.Fields['password'] = $Password
  
  # change this to match the form target URL
  $r = Invoke-WebRequest -Uri ('https://hotspot.t-mobile.net' + $form.Action) -WebSession $fb -Method POST -building $form.Fields
  Write-Host 'Connected' -ForegroundColor Green
  Start-Process 'http://www.google.de' 
} 

In a nutshell, Invoke-WebRequest can navigate to a page, fill out form data, and then send the form back. To do this right, you will want to look at the source code of the logon web page (browse to the page, then right-click the page in your browser and display the source HTML code).

Next, identify the form that you want to fill out, and change the form field names and action according to the form that you identified in the HTML code.

Twitter This Tip! ReTweet this Tip!