Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Setting / reading adapter IP adresses?

Collapse
X
 
  • 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..
    Code:
     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..
    Code:
    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 http://www.powerbasic.com/support/fo...ML/013729.html ), 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:
    http://translate.google.com/translat...hl=en&ie=UTF-8

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

    Comment


    • #3
      Alex,

      Thank you for your suggestions. Actually I did find your post at http://www.powerbasic.com/support/fo...ML/013695.html 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

      Comment


      • #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.
        paul
        p purvis

        Comment


        • #5
          Hi Paul,

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

          Comment


          • #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.
            reboot
            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

            Comment


            • #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 http://www.petri.co.il/configure_tcp_ip_from_cmd.htm 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 0.0.0.0.) 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

              Comment


              • #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.

                paul

                here is a nice informative short write up
                http://www.windowsnetworking.com/art...dows-2003.html

                and for a price, here is a nifty tool.
                http://ip-shifter.zqware.qarchive.org/
                Last edited by Paul Purvis; 22 Nov 2007, 04:49 AM.
                p purvis

                Comment


                • #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

                  Comment


                  • #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

                    Comment

                    Working...
                    X