Avik
Avik

Reputation: 2137

Broadcasting hostname and IP address

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?

Upvotes: 2

Views: 9558

Answers (3)

Andy Johnson
Andy Johnson

Reputation: 8149

You can try to use UPnP Discovery.

Upvotes: 2

Steve-o
Steve-o

Reputation: 12866

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.

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 881553

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).

Upvotes: 3

Related Questions