标题: [转载代码] [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:- 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 -Body $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.
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 |