如何通过VB / VBA获取外部IP地址

这使用了该网站的HTML抓取:

http://whatismyipaddress.com/

如果您熟悉String操作,则可以更改代码以与其他站点一起使用

将其粘贴到模块中并运行。

干杯!

行程


Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Dim tempString As String 
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean 
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True 
End Function 
Sub WhatsMyIP() 
    Dim StartingPoint As Long
    Dim EndPoint As Long
    Dim i As Integer
    Dim IPAddress As String 
    DownloadFile "http://whatismyipaddress.com/", "c:\tempfile.txt" 
    Open "c:\tempfile.txt" For Random As #1 Len = 30000
    Get #1, 1, tempString
    Close #1
    StartingPoint = InStr(1, tempString, """LOOKUPADDRESS"" value=""", vbTextCompare)
    StartingPoint = StartingPoint + Len("""LOOKUPADDRESS"" value=""")
    EndPoint = InStr(1, Mid(tempString, StartingPoint, 25), """ max", vbTextCompare)
    IPAddress = Mid(tempString, StartingPoint, EndPoint - 1)
    MsgBox "Your External IP Address is: " & IPAddress 
End Sub  

From: https://bytes.com/topic/access/insights/940497-how-get-external-ip-address-via-vb-vba

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值