I cannot get StrComp to work correctly and I'm not sure why. Can anyone see what I might be doing wrong here? (all ip numbers have been changed)
Option Explicit
Dim http : Set http = CreateObject( "MSXML2.ServerXmlHttp" )
Dim externalip
http.Open "GET", "http://icanhazip.com", False
http.Send
externalip = http.responseText
wscript.Echo externalip
wscript.Echo StrComp(externalip, "71.215.176.202")
if StrComp(externalip, "71.215.176.202") = 0 Then
wscript.Echo "Connected to Comcast"
else
wscript.echo "Connected to Office"
end if
Set http = Nothing
This will never return 0, even when externalip is correct. The strange thing is that there seems to be an extra CR/LF in the externalip. I've tried using the Trim function but that doesn't seem to help. Here's an example of the output while connected to the office:
C:\BATFiles>cscript ip.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
107.62.166.159
-1
Connected to Office
And here is the output when connected to my local ISP (Comcast)
C:\BATFiles>cscript ip.vbs
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
71.215.176.202
1
Connected to Office
I know from the output that I could just check if strcomp returns > 0, but the office ip is subject to change depending on which location I'm connecting to but the IP on my local is pretty much static. And I'm not quite sure how -1 and 1 are decided upon when doing a string comparison. Is it doing a length comparison?