Pelles C forum
C language => Beginner questions => Topic started by: delper on June 13, 2009, 09:44:41 PM
-
Hi C Wizards ...
Does anyone knows a simple way to read the computer IP address using C? And how to change it?
I guess I should use some weird WinAPI functions.... I just don't know which ones?
Regards
-
Hi C Wizards ...
Does anyone knows a simple way to read the computer IP address using C? And how to change it?
I guess I should use some weird WinAPI functions.... I just don't know which ones?
Regards
In the attachment you will find with a little program around a snippet of a tools I wrote some time ago. It displays you IP-adresse.
I am not sure if is possible to change you IP so easy, because you get your IP from an other device and you have to say that device to change your IP.
-
Your network (NIC) card comes from the manufacture with a hard wired address that it uses to communicate with the ISP. When your computer is first turned on, and when it connects to the ISP, the hardware and software automatically decide how they are are going to talk to each other, and what addresses they will accept as valid. The ISP assigns an Internet address to your computer (in most instances the address is different every time you log on). Unless you are only interested in setting up a private local network, you can not change the ISP assigned address or you will loose your internet connection.
-
Thanks a lot AlexN!!!!!
This is a good start..... I was getting bald on all this!. I have a few other functions to implement like get IP from DHCP or changed it as I mentioned before. Still don't know how to get there, but hopefully looking into the gethostname function I'll get somewhere....
Regards,
-
Thanks a lot AlexN!!!!!
No problem! ;)
A question: when you debug in this example, does the active line move correct?
-
Hi AlexN,
I don't know how to use the debug feature .... although I can try.
BTW, Do you know if there is any way to change the IP address through a single command line? If that exist, then I can take the IP and then issue a system call. I haven't found a way to do it yet. But I presume there must be a command to do that.
Regards
-
I don't know how to use the debug feature .... although I can try.
Go to project options and choose at the compiler full debug and at linker options Codeview and COFF. Rebuild the project. Then you can debug with F5 and F10/F11.
BTW, Do you know if there is any way to change the IP address through a single command line? If that exist, then I can take the IP and then issue a system call. I haven't found a way to do it yet. But I presume there must be a command to do that.
Why I don't know any tool to change my IP adress by command-line. When I want to change my IP-adress, I have to take connection with my router and tell it that I want to have an other (interneal) IP adress. And the IP of my internet connection I get each time new from my provider when I connect with the internet.
Why do you want to change your IP adress?
-
Hi AlexN,
Thanks for the Tip. I'll try this out later.
I need to be able to reconfigure my Ip address based on the customer side. I program embedded gadgets.
I found that the netsh command allows to do that. This is great. I don't have to bother on any WinAPI function to change it. I hope this will be portable to WinXP and Vista and Windows 7 ;-)
Regards,
D