The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on July 04, 2010, 01:22:38 PM

Title: Get Local address
Post by: Farabi on July 04, 2010, 01:22:38 PM
I got 5 computers connected to internet wirelessly. I want to retrieve the local address for each computers, so It can connect each other wirelessly directly without internet, how to do that?
Title: Re: Get Local address
Post by: box on July 04, 2010, 04:23:36 PM
You can generally use gethostname (http://msdn.microsoft.com/en-us/library/ms738527%28VS.85%29.aspx) and gethostbyname (http://msdn.microsoft.com/en-us/library/ms738524%28v=VS.85%29.aspx) to do this programmatically on windows 2000 and later. If I'm just testing a server program I usually just use ipconfig to get it's ip and hard-code it.
Title: Re: Get Local address
Post by: joemc on July 04, 2010, 05:37:05 PM
on each machine go to start -> run -> type "cmd" -> hit enter -> type "ipconfig" -> hit enter -> look at ip address

or use a web browser to connect to most "walmart" type routers. goto http://192.168.1.1 or 192.168.2.1 or could be many others depending on setup.   from the ipconfig look at "default gateway".  many times the router will show everyone that is connected.
Title: Re: Get Local address
Post by: dedndave on July 04, 2010, 06:15:04 PM
this won't help you if you are trying to write an all-purpose program
but, i use DHCP reservations
that way, each computer is assigned the same local IPA everytime
Title: Re: Get Local address
Post by: Farabi on July 05, 2010, 03:04:46 AM
Maybe someone experienced with iphlpapi.dll?

I saw this function there
Quote
GetIpAddrTable
The GetIpAddrTable function retrieves the interface–to–IP address mapping table.

What is interface mean? the WLAN hub or something?
Title: Re: Get Local address
Post by: Farabi on July 05, 2010, 03:06:12 AM
Quote from: box on July 04, 2010, 04:23:36 PM
You can generally use gethostname (http://msdn.microsoft.com/en-us/library/ms738527%28VS.85%29.aspx) and gethostbyname (http://msdn.microsoft.com/en-us/library/ms738524%28v=VS.85%29.aspx) to do this programmatically on windows 2000 and later. If I'm just testing a server program I usually just use ipconfig to get it's ip and hard-code it.

If I had the IP address should I ping it first before I can connect to it? I had no experience on networking.
Title: Re: Get Local address
Post by: Farabi on July 05, 2010, 03:19:47 AM
Quote from: joemc on July 04, 2010, 05:37:05 PM
on each machine go to start -> run -> type "cmd" -> hit enter -> type "ipconfig" -> hit enter -> look at ip address

or use a web browser to connect to most "walmart" type routers. goto http://192.168.1.1 or 192.168.2.1 or could be many others depending on setup.   from the ipconfig look at "default gateway".  many times the router will show everyone that is connected.

I tried to connect to http://192.168.1.1/ using browser and it show a webpage for setup my connection, what to do next?
Title: Re: Get Local address
Post by: box on July 05, 2010, 04:17:57 AM
Quote from: Farabi on July 05, 2010, 03:06:12 AM
If I had the IP address should I ping it first before I can connect to it? I had no experience on networking.
No need, just test whether connect() fails (TCP) or you get no response (UDP). If you are just using this on your own network you can use ping to make sure a given host is reachable, but it's not good practice to rely on pings if you are going to be connecting to other people at some point since they are sometimes disabled.


What exactly are you trying to do?
Title: Re: Get Local address
Post by: Farabi on July 05, 2010, 12:14:39 PM
Quote from: box on July 05, 2010, 04:17:57 AM
Quote from: Farabi on July 05, 2010, 03:06:12 AM
If I had the IP address should I ping it first before I can connect to it? I had no experience on networking.
No need, just test whether connect() fails (TCP) or you get no response (UDP). If you are just using this on your own network you can use ping to make sure a given host is reachable, but it's not good practice to rely on pings if you are going to be connecting to other people at some point since they are sometimes disabled.


What exactly are you trying to do?

Im going to make a local server for my campus, one of the computer will be the data storage so other computer can see the data but cant modify it.
Title: Re: Get Local address
Post by: Farabi on July 05, 2010, 01:35:10 PM
Okay I got it working.