No announcement yet.

Setting / reading adapter IP adresses?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting / reading adapter IP adresses?

    The laptops used at work frequently need to be re-configured to access HTML service interfaces via Ethernet in a number of different devices (radios, data recorders and such).

    So that the webpage-like interfaces can be opened in a browser window the LAN's TCP/IP interface needs to have appropriate static Network, Subnet and IP address set and of course each manufacturer has their own preferences.
    The laptops use WinXP Pro and do have one alternate set of IPs that will be applied if a DHCP connection fails but that's not enough!

    I'm putting together a utility program that will allow selection from a list of devices and will then automatically set the LAN IP addresses to suit.

    So far I'm shelling to Netsh.exe and achieving the required setup with eg..
     CommandLine = "netsh interface ip set address "+$Dq+"Local Area Connection"+$Dq+ _
                   " static "+IPAddress+" "+NetMask
     Shell Environ$("comspec") & " /C " & CommandLine, 0
    Once a netsh command has been sent to change the IP addresses, I can send another to check the new settings..
    CommandLine = "netsh interface ip show config"..
    The results can then be sent either to a text file or a named pipe for subsequent parsing.

    I tried reading the current / newly set IPs using Ipconfig.exe but found that it doesn't actually show the network adapter's static IP Address and NetMask unless there is an active network connection.
    The same seems to apply when using the API GetAdaptersInfo() (eg ), whereas Netsh.exe does reveal the adapter's Static IP addresses.
    This is probably more of a nuisance while I'm developing the program than it would be in actual use but still, I would prefer to use an API solution something like GetAdaptersInfo rather than the command shell if I can find one that works as well as Netsh.exe does.

    Can anyone suggest other (API?) methods for setting and reading a network adapter's TCP/IP properties?
    Rgds, Dave

  • #2
    I use VBscript to handle this job.
    Check Msg#3 here:

    Or you can do the same from PB by employ Jose's COM-wrapper


    • #3

      Thank you for your suggestions. Actually I did find your post at when I started looking into this.

      Initially I'm looking for 'regular API' type solutions. I'm putting off immersing myself into that whole WMI / COM thing for the time being.
      Rgds, Dave


      • #4
        Dave, i have an idea for you that might work.
        First, can you provide me with a list of the ip address, or at least there subnets.
        p purvis


        • #5
          Hi Paul,

          Here's the first couple of entries in the .INI file I'm using with my program..
          ;Ini file for IP Address Manager. 11/2007
          [Sailor LanBox - RT5022]
          Computer IP=
          Subnet Mask=
          IE Address=
          [Sailor SSAS H4122]
          Computer IP=
          Subnet Mask=
          IE Address=
          The IE Address key is the URL that we use with a browser to actually 'talk to' the device under test.
          Rgds, Dave


          • #6
            i was going to suggest something but i do not believe my orginal thought will help you.

            but try this,
            use one computer to test.
            inside network connection, click on your ethernet adapter and go into the advanced setting by way of properties from internet protocol tcpip, then add under ip settings additional ipaddresses that align to the ip addresses of your equipment along with the subnet of your equipment.
            in cmd prompt, do an ipconfig to review.
            then see if you can ping each piece of equipment's ip address
            then test the webpages on each equipment.
            if that works, let me know how you did because it sounds like you have good testing platform for the rest of use.
            Last edited by Paul Purvis; 22 Nov 2007, 01:39 AM.
            p purvis


            • #7
              Thanks Paul,

              The utility is working OK and I can connect with the different devices unter test.
              What I'm looking for a better way of setting the IP Addresses from within my program. Currently I'm using the command shell to run Netsh.exe and that works fine (See for tips on how to use netsh).
              I'm also using GetAdaptersInfo() to read the IP addresses to confirm that Netsh has done it's job and that is quite good (quick). Guess I'm looking for something like "SetAdaptersInfo()" to replace using Netsh to change the IPs .

              As an aside I have found that if the network adapter is unplugged, IPCONFIG and GetAdaptersInfo() will not report the IP addresses (IPCONFIG says "Media disconnected" and GetAdaptersInfo() reports IPs of this even if the adapter is not set to use DHCP ("Obtain an IP address automatically")and has IPs entered in "Use the following IP addresses".
              Not a big deal but it means that if I want to refresh the program's display of "Current IP addresses" whether the LAN cable is connected or not, I need to use Netsh again.

              Shelling to Netsh all the time makes the progam a bit sluggish...
              Rgds, Dave


              • #8
                i do not know how many times you have to change your ip address, but if it is not a great number, the way i said, you would not have to do nothing once the values are placed in except add or remove as your equipment changes.

                But if your happy, your happy.


                here is a nice informative short write up

                and for a price, here is a nifty tool.
                Last edited by Paul Purvis; 22 Nov 2007, 04:49 AM.
                p purvis


                • #9
                  Many thanks for those links Paul,

                  To date the INI file has five sets of addresses, there are another couple of address sets I need to add (equipment one of our branches has to service but I haven't had to work with yet) but I doubt that there would be many more than that. Perhaps one or two new sets to be added per year?

                  'IP Shifter' does most of what I need (interestingly it also won't play ball if there isn't an ethernet connection active..?)
                  All the same it is indeed a nifty tool

                  It can export 'profiles' to a text file, but doesn't seem to have an import option which is one of the features I wanted for my utility - that allows distribution of updated INI files by email as new devices come along.
                  The other data we need to associate with each set of IP addresses is the corresponding URL for the device's service interface (currently I launch IE with the URL as a parameter once the setup has been applied)
                  I'll have to see if the author of IP Shifter is open to New Feature requests

                  Meanwhile I've found references to AddIPAddress() that looks like it may be the missing fuction that I hoped to find. I didn't find any code samples though and I haven't got my head around it yet. Any PB'ers out there that have used this function before?
                  Rgds, Dave


                  • #10
                    when you do not have an net adapter plugged in or installed
                    you may need to look at installing "microsoft loopback adapter"
                    it creates a virtual adapater.
                    p purvis