1

I'm a Linux guy. I have a pretty specific problem I'm trying to solve on a Windows box, so please forgive my ignorance here.

PROBLEM (this can't be redefined): I have a windows machine that has 3 NICs. Each time it is booted, I need a way to dynamically and automatically set its IP addresses. Each time this machine is booted, it will have different address information. The machine will have a file consisting of name/value pairs accessible to it when it starts up (i.e. a file full of "=" entries). I need to perform all these tasks using standard windows command prompt commands run from a batch file. I don't have VB or anything available to me.

BIGGEST ISSUE: This would be much easier, I think, if Windows was deterministic with the naming of its network interfaces. If it was, I could parse this file and simply set, say, "Local Area Connection 2"'s IP address using netsh. As it stands, though, Windows will sometimes move around the names it uses for your physical NICs. So what's "Local Area Connection 2" today may just be "Local Area Connection" tomorrow. So, I have to find a way to determine these things during startup by using the MAC address and finding the corresponding NICs. Without grep, awk, etc, snagging this information from the ipconfig output is becoming increasingly difficult.

WHAT I'VE TRIED/ACCOMPLISHED: (1) I've figured out how to kick off my batch file during windows startup by adding a windows setting startup script through the local group policy editor. (2) I've figured out how to, from a batch file, parse my name/value pair file and grab the tokens. (3) I've tried using the arp command to set the ip mapping. This, as is obvious, simply routes packets correctly to an interface. Once the packets hit the interface, though, they get dropped because the packets are intended for a network that the NIC doesn't belong to. This does me no good. I need to set the ip addresses for the NICs.

MY CURRENT PLAN / WHAT I NEED HELP WITH: (1) Parse my name/value pair file (2) Find the names of the network cards that correspond to the mac addresses in the name/value pair file (3) Use netsh to set the ip addresses of these cards (4) Do this all from a batch file (5) Try not to complain as much that I'm not using a Linux box :-)

Any help is greatly appreciated.

7
  • 1
    Have you considered using a powershell script instead of a cmd.exe script? Is there really any reason you can't use an executable (perhaps written in C) instead of a batch file? Apr 3, 2012 at 23:06
  • I've never used (or heard of) powershell before. I just verified that I can run "powershell.exe" from the command line, though, so this may be an option if I can accomplish all the above using that tool and if it can run at startup.
    – Allen
    Apr 3, 2012 at 23:41
  • I haven't gotten around to learning Powershell yet myself (and if it was me, I'd solve your problem with an application written in C) but it should do everything you need. Start here: technet.microsoft.com/en-us/scriptcenter/dd742419.aspx Apr 4, 2012 at 2:35
  • I think this is definately do-able. Can you post an example of your name/value pair file?
    – iesou
    Jun 29, 2012 at 15:18
  • I know it it's pretty old, do you still need this resolved?
    – wmz
    Jul 28, 2012 at 17:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.