views:

6839

answers:

3

I have written some VBScripts to automate tasks that I perform on computers over the network. These work great for most tasks however within our network we have problems with the IP address in DNS being correct all the time. This mainly occurs with laptops where we have different IP ranges for machines on the wireless and wired network.

For example a machine may boot up wired in the morning and get an IP address: 10.10.10.1

When it switches to wireless it will obtain an address in a different subnet: 10.11.10.1

When you try to connect to that machine it still returns the old IP address (10.10.10.1) even though the computer now has a new one.

I have found that I can still connect to that computer's C$ share via \computer name\c$ even though the machine does not ping. Obviously there is some other kind of address resolution going on, my question is how do I harness this to allow my VBScripts connect to WMI?

Thanks!

A: 

From my own experience I have found the Microsoft TechNet ScriptCenter has just about anything you could ever want relating to VBScript. That's generally where I start when I want to delve into a new area of VBScript that I haven't previously explored.

The WMI FAQ on the Microsoft TechNet website has links to the ScripCenter along with links to many other usefule sites for learning how to script WMI. I would recommend finding a script that already does what you want since someone is bound to have already written what you need.

The article Automating TCP/IP Networking on Clients may have what you need to get started with resolving this problem.

Registered User
This is not exactly what I am looking for. The goal is to be able to determine the IP address of a machine, remotely ignoring the value in DNS for the workstation. I have looked for a solution to this in the script center in the past without success.
+1  A: 

If DNS doesn't have the correct address, then perhaps it is likely being resolved with NetBios. What you would have to do is resolve the computer name with either a WINS Server or through Broadcasts to the network. Depending on your network environment you would use one or both of those options.

Microsoft has a tool called NBLookup which should be able to lookup the name from WINS at the very least.

You can call NBLookup and parse the results. I don't recall another method for NetBios resolution natively within VBScript, but I haven't looked awfully hard recently.

Rob Haupt
That was exactly what I was looking for. I was able to use that utility and parse the results just as you suggested in order to get the IP address of the machine. Thanks!
+1  A: 

Your problem is name resolution. Windows uses 2 types of name resolution: DNS and NetBIOS.

DNS will resolve a name like .comcast.net or www.google.com NetBIOS resolves names that are 15 characters or less, like your computer name likely is.

When your computer looks for a name it doesn't know how to turn into an IP address, it goes to a DNS server and/or uses NetBIOS name resolution. Once it's looked up a name, it saves it in a cache for some period of time (usually about an hour) before looking it up again.

You can look at the list of names your computer has cached for each type of name resolution using the command-line this way:

DNS
  ipconfig -displaydns
NetBIOS
  nbtstat -c

Each of those commands also alllows you clear that cache as well, which will force your system to rediscover what IP address the name points to. Here are those commands:

DNS
  ipconfig -flushdns
NetBIOS
  nbtstat -R

Between those commands, you should be able to determine which type of name resolution is the culprit and resolve it by flushing that cache.