返回列表 发帖

[技术讨论] PowerShell Invoke-WebRequest获取本机外网IP地址

  1. # requires -Version 3.0
  2. $url = 'http://ip.qq.com'
  3. Invoke-WebRequest -Uri $url -UseBasicParsing | %{
  4.     if ($_ -match "ip_contend") {
  5.         $ExtIP = $_.InputFields.value | select -first 1
  6.     }
  7. }
  8. $ExtIP
复制代码
环境所限,需要使用 PowerShell 2.0 版本。

Invoke-WebRequest真是个好东西,等于wget+CURL

TOP

返回列表