NO

Author Topic: How to get the IP Address and changed it using C???  (Read 3975 times)

delper

  • Guest
How to get the IP Address and changed it using C???
« 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

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: How to get the IP Address and changed it using C???
« Reply #1 on: June 14, 2009, 12:14:47 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

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.
best regards
 Alex ;)

jwzumwalt

  • Guest
Re: How to get the IP Address and changed it using C???
« Reply #2 on: June 15, 2009, 01:20:19 AM »
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.

« Last Edit: June 15, 2009, 08:39:45 AM by jwzumwalt »

delper

  • Guest
Re: How to get the IP Address and changed it using C???
« Reply #3 on: June 16, 2009, 03:24:42 AM »
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,

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: How to get the IP Address and changed it using C???
« Reply #4 on: June 16, 2009, 12:35:37 PM »
Thanks a lot AlexN!!!!!
No problem! ;)

A question: when you debug in this example, does the active line move correct?
best regards
 Alex ;)

delper

  • Guest
Re: How to get the IP Address and changed it using C???
« Reply #5 on: June 17, 2009, 03:42:53 PM »
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

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: How to get the IP Address and changed it using C???
« Reply #6 on: June 17, 2009, 06:47:08 PM »
     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?
best regards
 Alex ;)

delper

  • Guest
Re: How to get the IP Address and changed it using C???
« Reply #7 on: June 17, 2009, 08:25:02 PM »
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