Board logo

标题: [转载代码] [PowerShell每日技巧]自动连接公共热点或登录网站(20140307) [打印本页]

作者: DAIC    时间: 2014-3-8 14:25     标题: [PowerShell每日技巧]自动连接公共热点或登录网站(20140307)

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:
  1. function Start-Hotspot
  2. {
  3.   param
  4.   (
  5.     [System.String]
  6.     $Username = 'XYZ@t-mobile.de',
  7.     [System.String]
  8.     $Password = 'topsecret'
  9.   )
  10.   # change this to match your provider logon page URL
  11.   $url = 'https://hotspot.t-mobile.net/wlan/start.do'
  12.   $r = Invoke-WebRequest -Uri $url -SessionVariable fb
  13.   $form = $r.Forms[0]
  14.   # change this to match the website form field names:
  15.   $form.Fields['username'] = $Username
  16.   $form.Fields['password'] = $Password
  17.   # change this to match the form target URL
  18.   $r = Invoke-WebRequest -Uri ('https://hotspot.t-mobile.net' + $form.Action) -WebSession $fb -Method POST -Body $form.Fields
  19.   Write-Host 'Connected' -ForegroundColor Green
  20.   Start-Process 'http://www.google.de'
  21. }
复制代码
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.

http://powershell.com/cs/blogs/tips/archive/2014/03/07/auto-connecting-with-public-hotspot.aspx
作者: 522235677    时间: 2014-3-8 14:49

PowerShell为何比批屌




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2