tags:

views:

309

answers:

4

In order to notify all computers within the same lan about my existence, I want to broadcast my hostname and IP address. How do I go about doing so without sending them as a string?

+1  A: 

Avik, this is what DNS is meant to be used for. While "regular" DNS is meant to hold names and IP addresses for each machine (statically configured), there is a dynamic DNS protocol which allows machines to update their DNS entries in real time.

This sort of capability is used in some of the office environments for my clients where printers on a machine are shared but the machines they're attached to use DHCP (meaning their IP address can change).

See here and here for details and the Windows implementation with DHCP.

Lets call your machine that wants to advertise itself the SERVER and all the machines that can use it, the CLIENTS.

Of course, dynamic DNS only notifies DNS itself of the name/IP mapping and is useful if the CLIENTS are already aware of your SERVER so they can get the IP address from DNS. If you have no way for CLIENTS to discover that your SERVER has just been added, you'll still need to broadcast a packet occasionally indicating that your SERVER exists (this will only need the SERVER name since CLIENTS will use DNS to get the IP address).

This broadcast packet should be picked up by all CLIENTS and kept in a local table. If the communications from a CLIENT to your SERVER fails, the local table entry for your SERVER should be removed (it'll be re-added when your SERVER broadcasts again).

paxdiablo
A: 

Are you trying to do this in a specific programming language, or is this a conceptual question? If you're trying to actually implement this, is this intended to be practical or just for learning & understanding purposes?

Matt Ball
A: 

Basically re-inventing NetBIOS or ZeroConf, as popular with small embedded devices for discovery by a Windows or OS X based installer or setup utility.

Steve-o
A: 

Maybe use UPnP Discovery?

Andy Johnson