python - 在不访问任何页面的情况下获取我的 vpn 提供的 IP 地址
问题描述
我使用 vpn 并使用 selenium 连接到网站。我可以通过访问http://ipconfig.io/ip查看我从 vpn 提供的 IP 。我的问题是,当我使用 vpn 时,https://ipinfo.io/ip网站提供了我与 vpn 一起使用的 ip。我可以使用 vb6 或 python 做同样的事情吗?还是用硒?
解决方案
您可以在 VB6 中从http://ipconfig.io/ip “下载”页面,并从原始 html 解析地址。这是Dyn 提供的原始http://checkip.dyndns.org中的一个pvGetExternalIP
函数。
Private Function pvGetExternalIP() As String
Dim sResponse As String
With New cAsyncSocket
.SyncConnect "checkip.dyndns.org", 80
.SyncSendText "GET / HTTP/1.1" & vbCrLf & "Host: checkip.dyndns.org" & vbCrLf & vbCrLf
Do
sResponse = sResponse & .SyncReceiveText()
If InStr(sResponse, vbCrLf & vbCrLf) > 0 Then
With CreateObject("VBScript.RegExp")
.Pattern = "\d+\.\d+\.\d+\.\d+"
sResponse = .Execute(sResponse).Item(0)
End With
Exit Do
End If
Loop
End With
If sResponse Like "*.*.*.*" Then
pvGetExternalIP = sResponse
Else
pvGetExternalIP = "127.0.0.1"
End If
End Function
这使用原始 http 请求并解析原始 http 响应。
推荐阅读
- laravel - 请求数组的附加值在 Laravel 控制器中消失了
- python - 如何在嵌套的 if 语句中增加一个 for 循环
- python-3.x - 如何在 Ubuntu 上进入根目录然后在 Python3 中执行 shell 命令?
- node.js - 在 npm install 命令中面临“JSON 输入意外结束”问题
- python-3.x - RuntimeError:给定组 = 3,大小为 12 64 3 768 的权重,预期输入 [32、12、30、768] 有 192 个通道,但有 12 个通道
- ios - 如何正确添加 HKRoute 到 HKWorkout
- java - Spring路径变量url
- javascript - 为不同语言和平台制作库的有效方法
- docker - 试图弄清楚如何为 docker 容器化这个可执行文件
- java - 如何删除 ArrayList 中的元素?