首页 > 解决方案 > 在不访问任何页面的情况下获取我的 vpn 提供的 IP 地址

问题描述

我使用 vpn 并使用 selenium 连接到网站。我可以通过访问http://ipconfig.io/ip查看我从 vpn 提供的 IP 。我的问题是,当我使用 vpn 时,https://ipinfo.io/ip网站提供了我与 vpn 一起使用的 ip。我可以使用 vb6 或 python 做同样的事情吗?还是用硒?

标签: pythonseleniumvb6ip

解决方案


您可以在 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 响应。


推荐阅读