vbScript that Checks NetworkAdapter Config and updates URL if it detects change

61 Views Asked by At

Ok... everyone here seems to be way more educated about this stuff than I. But I've been at this for 2 days straight and I've gone at it from all kinds directions.

Goal:

Have a script check the IP address of local pc. At some time (thinking 5 minutes) recheck the IP address again. Compare the two and if there is a change execute a command silently.

I realize that I can not just get the IP address as I'll get the entire state using winmgmts and I'm ok with that. Really it's just to keep an eye on whether or not the state changes in general. The line of code is to access a URL which will update my FreeDNS incase the IP changes. For whatever reason, none of the programs offered have been working. One even crashes .Net Framework.

Knowing that I'm an utter noob (and thank you for reading this far!) here's what my crazy broken and utterly bizarre code looks like. Any assistance would be divine and I apologize

Dim firstSet, secondSet

Set objWMIService = GetObject("winmgmts:")
Set FirstIP = objWMIService.ExecQuery("SELECT * FROM " &    "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set firstSet = FirstIP

WScript.Sleep 3

Set objWMIService = GetObject("winmgmts:")
Set SecondIP = objWMIService.ExecQuery("SELECT * FROM " & "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set secondSet = SecondIP

results = StrComp(firstSet, secondSet, 1)

If Not results = True Then
    updateURL = "MyURL"
    Set req = CreateObject("MSXML2.XMLHTTP.6.0")
    req.Open "GET", updateURL, False
    req.Send
End If
0

There are 0 best solutions below