找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 14268|回复: 1

[转载代码] [PowerShell每日技巧]自动连接公共热点或登录网站(20140307)

[复制链接]
发表于 2014-3-8 14:25:30 | 显示全部楼层 |阅读模式
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
发表于 2014-3-8 14:49:05 | 显示全部楼层
PowerShell为何比批屌
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 23:45 , Processed in 0.012820 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表