[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[转载代码] [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

PowerShell为何比批屌

TOP

返回列表