I need a function that returns the external ip address as a string for use inside a Microsoft Access application. My efforts to find one thru searching google and bing produce answers that do not work in Access/VBA.
Thanks.
Thanks.
Dim varRetVal Dim strLine As String Dim strDefaultGateway As String Dim strSubNetMask As String Dim strIPAddress As String Dim strDHCPServer As String Const conPATH_TO_FILE As String = "C:\Test\IPConfig.txt" varRetVal = Shell("cmd.exe /c IPConfig /all > " & conPATH_TO_FILE, vbHide) Open conPATH_TO_FILE For Input As #1 Do While Not EOF(1) Line Input #1, strLine If InStr(strLine, "IP Address") > 1 Then strIPAddress = Mid$(strLine, InStr(strLine, ":") + 1) Debug.Print "The IP Address of the Local PC is: " & strIPAddress ElseIf InStr(strLine, "Subnet Mask") > 1 Then strSubNetMask = Mid$(strLine, InStr(strLine, ":") + 1) Debug.Print "The IP Address of the Subnet Mask is: " & strSubNetMask ElseIf InStr(strLine, "Default Gateway") > 1 Then strDefaultGateway = Mid$(strLine, InStr(strLine, ":") + 1) Debug.Print "The IP Address of the Default Gateway is: " & strDefaultGateway ElseIf InStr(strLine, "DHCP Server") > 1 Then strDHCPServer = Mid$(strLine, InStr(strLine, ":") + 1) Debug.Print "The IP Address of the DHCP Server is: " & strDHCPServer End If Loop Close #1 ' Close file.
The IP Address of the Local PC is: 192.168.1.101 The IP Address of the Subnet Mask is: 255.255.255.0 The IP Address of the Default Gateway is: 192.168.1.1 The IP Address of the DHCP Server is: 192.168.1.1
Function GetExternalIPAddress() As String On Error GoTo GetExternalIPAddress_Error Dim iebrowser As InternetExplorer Dim dtStartTime As Date Dim sDocHTML As String Dim strIPAddress As String 'Create a browser object Set iebrowser = CreateObject("internetexplorer.application") iebrowser.Navigate "http://www.whatismyip.com/automation/n09230945.asp" 'Wait for the page to load dtStartTime = Now Do While iebrowser.readyState <> READYSTATE_COMPLETE If DateDiff("s", dtStartTime, Now) > 10 Then GoTo GetExternalIPAddress_Timeout Loop 'Get the page contents sDocHTML = iebrowser.Document.documentElement.innerHTML 'destroy the browser object Set iebrowser = Nothing strIPAddress = Mid(sDocHTML, InStr(sDocHTML, "<BODY>") + 6, InStr(sDocHTML, "</BODY>") - InStr(sDocHTML, "<BODY>") - 6) GetExternalIPAddress_Exit: GetExternalIPAddress = strIPAddress Exit Function GetExternalIPAddress_Timeout: strIPAddress = "Timeout" GoTo GetExternalIPAddress_Exit GetExternalIPAddress_Error: strIPAddress = "Error" Resume GetExternalIPAddress_Exit End Function
Comment