Click here to Skip to main content
Click here to Skip to main content

Change TCP/IP network settings remotely.

By , 8 May 2000
 
  • Download source files - 8 Kb
  • Executable - 7 Kb
  • Introduction

    How to change TCP/IP network settings remotely on a bare bone system?

    Situation

    • Embedded NT4.0 machine, with minimal OS configuration.
    • No keyboard (NULL keyboard driver), no screen (NULL video driver).
    • Only a network connection can be used to reach the Embedded machine.

    Problem

    • How do we change the computer and network host name?
    • How do we choose between the usage of DHCP or a static IP address?
    • How do we change the static IP address?

    Solutions

    • Connect with a tool like vnc, pc-anywhere, … change the network settings with the control panel. (But a bare bone system does not have a control panel).
    • Connect with regedt32.exe (or another registry editor) remotely to the Embedded machine and change all the necessary registry entries. (Not a very good solution to use in production and what happens when you want to change something in the field?)
    • Use IPConfig.exe (which can be found in the NT resource kit but it only handles part of the required functionality)
    • Write your own program to manipulate the registry remotely.

    References:

    By using the information provided by the CodeGuru article "Change IP Address and HostName of NT machine" by Massimo Negroni and the MSDN article Q194407, together with the excellent Registry API wrapper classes of Len Holgate (http://www.codeproject.com/system/cregistrykey.asp), I wrote a little Win32 command line program to change the mentioned registry settings. A reboot is required after the changes. (If somebody knows of a way to change an IP address without a reboot on NT4, let me know)

    The Program:

    When should you use it?

    If the following sentences give a complete description of your personality then use use it!

    • I am a command line freak.
    • I need to program for Embedded NT 4.0
    • I like to live dangerously
    • I am a sys admin who wants to change static IP addresses across the network for Target NT machines that only have one (1!) network card.

    Like with all registry manipulations, you should make a backup of the registry before attempting to change it. Believe me, whilst debugging this little program I sure messed up a system registry or two… Use at your own risk. (NB: that means first test it for your specific network configuration on a ‘test’ machine).

    Implementation information

    The most important Registry keys to use and/or modify are:

    • HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\DHCP
    • HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1
    • HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\(network card name)\\Parameters\\TCPIP
    • HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\TcpIp\\Parameters

    Build information

    • Download Len Holgate’s Registry API wrapper source
    • Create a Win32 Multithreaded DLL Console project an put Main.cpp, NWConnectionSettings.h and NWConnectionSettings.cpp together with the Registry API wrapper classes inside the same directory (and project).

    Usage information:

    • If no command line parameter is supplied, the settings of the local computer are retrieved.
    • To retrieve and change settings of a remote Network computer, specify the network computer name as parameter.
    • Administrator Privileges are required for the program to function properly.
    • Intended for use on NT 4.0 or NT Embedded 4.0

    Posted for all struggling Embedded NT dudes.

    Best Regards,
    GBO.

    License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    About the Author

    Gert Boddaert
    Technical Lead rtos.be
    Belgium Belgium
    Member
    Gert Boddaert is an experienced embedded software architect and driver developer who worked for companies such as Agfa Gevaert, KBC, Xircom, Intel, Niko, (Thomson) Technicolor, Punch Powertrain, Fifthplay, Cisco and Barco. For more obscure details, please take a look at his LinkedIn profile. Anyway, he started out as a Commercial Engineer – option “Management Informatics”, but was converted to the code-for-food religion by sheer luck. After writing higher level software for a few years, he descended to the lower levels of software, and eventually landed on the bottom of embedded hell… and apparently still likes it down there.
     
    His favourite motto: “Think hard, experiment and prototype, think again, write (easy and maintainable) code”,
     
    favourite quote: “If you think it’s expensive to hire a professional to do the job, wait until you hire an amateur.” – by Red Adair,
     
    I can be contacted for real-time embedded software development projects via http://www.rtos.be and http://www.rtos.eu

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    QuestionConnecting with Hostname to host with Static IP Addressesmemberddas774 Sep '07 - 5:58 
    I am using Windows Sockets 2 (winsock2.h) for a program that will connect to a host computer named MyHost that runs a HTTP server, listening on Port 80.
     
    MyHost has DHCP enabled & the IP assigned to it automatically is, say 157.184.205.117.
     
    My program connects to the host computer using its Hostname & not its IP address. (this is a requirement)
     

    On running my program on my local computer:
     
    1. I can successfully connect to MyHost using HTTP over TCP/IP on Port 80.
    2. I can successfully send [send()] data to MyHost.
    3. I can successfully receive [recv()] the response from MyHost.
     
    All communication is absolutely fine & works well.
     

    Now here's problem:
     
    If now - I turn off DHCP on MyHost & provide it a static IP address, say 157.184.205.111 - my program cannot connect to MyHost anymore.
     

    I have also observed the following:
     
    1. If, from within my program, I try to resolve the IP address of MyHost using the gethostbyname() function & other calculations, I receive the same old IP address of MyHost (157.184.205.117) instead of the newly assigned static IP address (157.184.205.111).
     
    2. If I PING to MyHost from the Windows XP Command Prompt, it tries to connect to the old IP address of MyHost (157.184.205.117) instead of the newly assigned static IP address (157.184.205.111). So pinging also fails.
     
    3. If I try to open in Internet Explorer, the url "http://MyHost" it fails to open the address.
     

     
    Before assigning the host the static IP address, everything worked fine:
    1. My Socket program connected.
    2. Ping worked.
    3. Internet Explorer worked.
     

    Does anyone know a way to work around this problem?
     
    That the hostname "MyHost" will be used to connect to the host, is a requirement.
     
    The whole thing is getting me confused. Confused | :confused: Confused | :confused:
     

    Questionhow to assign IP address of remort Ethernet port?memberAji V Nair10 May '07 - 2:55 
    hello,
     
    i have a device with Ethernet port, i have the MAC address of that device,
     
    i want to set custom ip address to that ethernet port remotely from a PC.
     
    if u know any APIs plz reply me,
     
    that will be of gr8 help to me.
     
    Thanks in advance
    Ajith

     
    Ajith

    QuestionSet IP address???memberBasavaraj P.Umadi14 Feb '05 - 20:09 
    hello,
     
    i have a device with Ethernet port, i have the MAC address of that device,
     
    i want to set custom ip address to that ethernet port remotely from a PC.
     
    if u know any APIs plz reply me,Confused | :confused:
     
    that will be of gr8 help to me.Smile | :)
     
    - thanks,
    Basavaraj P.Umadi
    GeneralhisussAnonymous4 Nov '03 - 23:34 
    hi
    GeneralMultiple Network Cardsmemberjjadkins5 Aug '03 - 11:21 
    I know this program only works if you have one network card. I have a need to be able to set the ip address on computers with more than one network card. However, instead of setting all of the network cards to the same ip address, I need to be able to set the ip address of the active network card. For instance, my laptop has wired and wireless network adapters. I only want to change the ip address of the wired adapter, but not the wireless one. My program has to be able to work on any Windows computer (NT, 2000, or XP) with multiple network adapters. Does anybody have any suggestions?
    Generalproblemmembernehaddit19 Mar '03 - 0:02 
    I tested Gert Boddaert's tool and got an error message. The reason: The tool searches in SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1 for the name of the network card adapter. I had installed a second adapter and removed the first one, so that my computer has no such entry - it has ...\\NetworkCards\\2 instead.
     
    When compiling the software I had to download CRegistry.zip and found here another error: in "RegistryKey.cpp" the module
    "bool CRegistryKey::QueryValue( LPCTSTR pValueName, DWORD >&dwValue)" does not set "ok=true" on success so it always returns false ...
     
    Besides this, it works! But it does not solve the main problem: to change the IP address without rebooting - there are some undocumented dll entries anywhere! Open sources ??!!
     

     

     
    neha
    GeneralRe: problemsussShimmerCN2 Jun '03 - 23:57 
    I've tryed to change a machine's ip these days.
     
    In SDK document, IP Helper Api told us, we can use "AddIPAddress" and "DeleteIPAddress" to change the machine's IP. But "AddIPAddress" can only add none persistent IP, and "DeleteIPAddress" can not delete the current IP address.(PS: this current IP is not the CurrentIpAddress of the PIP_ADAPTER_INFO structure. We can band more than one IP to an adapter, but in the control panel we can see only one. So I called such IP as the current ip. If somebody knows what's this means, would u tell me?)
    So I think "AddIPAddress" and "DeleteIPAddress" can only maintain the none persistent IP. These two functions dosen't change the register, but change the real network settings, although it's functions is too puny.
    On the other way, I used "netsh"(a command in Windows2000). This command can maintain the "persistent". It gets the network parameters from register, and renew the register after it changed the parameters. Of course, netsh is not only a "regiter tool". It also can change the real parameters without reboot.
    IP Helper API is not a powerful enough API. But in netsh, Microsoft can change the network settings freely. So I guess, Microsoft used another API to apply the network parameters to take effect. Perhaps it's an API without open.
     
    Thanks for your reading
    GeneralRe: problemmemberDimitris Vassiliades7 Jul '04 - 22:36 
    You can add more than one IP addresses to an adapter from the control panel as well (works on Win2k, XP - cannot recall the procedure for NT4).
     
    Select the Internet Protocol(TCP/IP) and Press Properties. Give the first IP address and press the Advanced button. Now you can Add in "IP Settings" Tab as many ip addresses you want.
     

    ...Plug & Pray... Dead | X|
    Generalnetwork shellmemberbobkoure2 Jan '02 - 8:28 
    >Problem
    >How do we change the computer and network host name?
    >How do we choose between the usage of DHCP or a static IP address?
    >How do we change the static IP address?
     
    There's a command-line utility in Win2K (maybe not in NT?) called netsh that allows you to do the last two items.
    For instance
    netsh interface ip set address "Local Area Connection" dhcp
    sets the interface to DHCP, and
    netsh interface ip set address "Local Area Connection" static %StaticIP% 255.255.255.0 %GateIP% 1
    sets the interface to static, defines an IP, a netmask and a default gateway IP (note - use real IPs or set the environment variables StaticIP, etc. ...)
     
    The flag –r (then followed by an IP or machine number) specifies execution on a remote machine. (I haven't experimented with this one, though...).
     
    I'm not sure how ipconfig can help with any of this.
     
    Bob
    PS: I did some work with NT/E some years ago. As I remember, the recommended way to use the console in a headless system was to log in using NetMeeting. You had to request a connection with the target machine name itself (not some person or process at the machine), the connection had to be "private" (or something like that) and the account you were calling from had to be part of the administrators group on the target machine. The advantage of NetMeeting was that it was "free" as it came with NT and W2K - so it didn't add to the total system cost we were asking customers to pay.
     

    GeneralGetting Netcard problem, error in registry wrapper ...memberWerner Wittig27 Mar '01 - 23:31 
    I tested Gert Boddaert's tool and got an error message. The reason: The tool searches in SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\1 for the name of the network card adapter. I had installed a second adapter and removed the first one, so that my computer has no such entry - it has ...\\NetworkCards\\2 instead.
     
    When compiling the software I had to download CRegistry.zip and found here another error: in "RegistryKey.cpp" the module
    "bool CRegistryKey::QueryValue( LPCTSTR pValueName, DWORD >&dwValue)" does not set "ok=true" on success so it always returns false ...
     
    Besides this, it works! But it does not solve the main problem: to change the IP address without rebooting - there are some undocumented dll entries anywhere! Open sources ??!!
     

     
    Werner

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web03 | 2.6.130523.1 | Last Updated 9 May 2000
    Article Copyright 2000 by Gert Boddaert
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid