Multiserver, multiclient, IP Address DCHP nightmare from hell

P

pigeonrandle

Hi,
This started off being a question along the lines of "how do i get the
local machine ip address?", which can be done using ....

String sIPAddress =
Dns.Resolve(System.Environment.MachineName).AddressList[0].ToString

unfortunately, the [0] bit reminded me that a computer can have more
than one IP (technically, i hadn't forgotten, it had just become
obfuscated due to the hashing effect of alcohol).

So anyway(!), i have a server app (that can be installed on several
machines on a network) and a client app (several instances again), but
the servers could be sat on machines that have DHCP IP addresses.

What's the best way to get the clients to find the server if its IP has
changed?

I was considering using some form of broadcast from the server that
would perpetuate until it 'knew' all the clients had found its new
location? And this is where the multiple IP addresses come in beacuse i
also need to know if the AddressList always enumerates the IP's in the
same order (what if a network adapter had broken, etc), because my
server needs to know which IP it should be broadcasting to the clients.

Afterthought!: Is there a way to find out the MAC address of an IP
because i could use that?

Thankyou in advance you clever people you!
James Randle.
 
G

Guest

A relatively simple way would be to have the server, when it is started,
update a row on a database with it's current IP address.
Each client, when it starts, can either query the database, or hit a
webservice which would return the correct IP address to look for.
Peter
 
P

pigeonrandle

I've found some code to get the MAC Address, but it seems to be
returning *a lot* of addresses. Does anyone know why this is happening?

ManagementObjectSearcher wmiObj= new ManagementObjectSearcher("select
AdapterType, MACAddress from Win32_NetworkAdapter");

foreach (ManagementObject item in wmiObj.Get())
{
MessageBox.Show((string)item["MACAddress"] + " | " +
(string)item["AdapterType"]);
}

I have one wireless and one wired adapter, but this code returns 17
rows! Some are actually blank, which is akin to my current facial
expression.

Thanks,
James Randle.
 
P

pigeonrandle

Peter,
Thanks for your suggestion, i like it! Alas though, i want to avoid
using anything outside of my control (like a database that someone
could muck up, or even better delete because they dont know what it is
there for ..! once bitten, etc).
I had considered a similar solution using a file on a shared folder,
but i reckon the broadcast solution is 'optimal' :blush:).

As long as i can find out what NIC was selected (by the IP they choose)
when the server is set up, i can use the (stored) MAC to check if the
IP has changed after the server has restarted. I can then broadcast the
change until all the clients 'know'.

In a perfect world i would definitely go for the database option, but
as we both know this world is far from perfect!

Thanks again,
James.
A relatively simple way would be to have the server, when it is started,
update a row on a database with it's current IP address.
Each client, when it starts, can either query the database, or hit a
webservice which would return the correct IP address to look for.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




pigeonrandle said:
Hi,
This started off being a question along the lines of "how do i get the
local machine ip address?", which can be done using ....

String sIPAddress =
Dns.Resolve(System.Environment.MachineName).AddressList[0].ToString

unfortunately, the [0] bit reminded me that a computer can have more
than one IP (technically, i hadn't forgotten, it had just become
obfuscated due to the hashing effect of alcohol).

So anyway(!), i have a server app (that can be installed on several
machines on a network) and a client app (several instances again), but
the servers could be sat on machines that have DHCP IP addresses.

What's the best way to get the clients to find the server if its IP has
changed?

I was considering using some form of broadcast from the server that
would perpetuate until it 'knew' all the clients had found its new
location? And this is where the multiple IP addresses come in beacuse i
also need to know if the AddressList always enumerates the IP's in the
same order (what if a network adapter had broken, etc), because my
server needs to know which IP it should be broadcasting to the clients.

Afterthought!: Is there a way to find out the MAC address of an IP
because i could use that?

Thankyou in advance you clever people you!
James Randle.
 
W

WTH

What's the best way to get the clients to find the server if its IP
has changed?

Use a name which will be resolved (by you) via DNS instead of the IP
Address. We have this situation with our product in the field. Customers
who use DHCP without reservations on the IP Addresses and customers who
change names but not IP addresses. Our system lets them specify either the
IP Address or the name of the machine. We occasionally get customers who
like to change both, but let's not talk about them ;)... This should also
resolve your multi-card server issues as only one of them will be bound by
DNS to a particular name.

WTH
 
W

WTH

Use a name which will be resolved (by you) via DNS instead of the IP
Address. We have this situation with our product in the field. Customers
who use DHCP without reservations on the IP Addresses and
customers who change names but not IP addresses. Our system lets
them specify either the IP Address or the name of the machine. We
occasionally get customers who like to change both, but let's not
talk about them ;)... This should also resolve your multi-card
server issues as only one of them will be bound by DNS to a
particular name.
WTH

This must have occurred to you already, did I miss something in your problem
description?

Are you aware that you can't use two network interfaces from the same
machine on the same network? Just checking. By this I mean that if you
have a machine with four cards, only one of them will interface to a
particular network.

WTH
 
P

pigeonrandle

WTH,
Thankyou for replying.

I was, infact, unaware that you couldn't have two network cards
connecting to the same network. That's the best news i heard all day!

Thankyou,
James Randle.
 
W

WTH

WTH,
Thankyou for replying.

I was, infact, unaware that you couldn't have two network cards
connecting to the same network. That's the best news i heard all day!

Thankyou,
James Randle.

Lol, no problem. Now, I don't know how true this is for other operating
systems, but Windows won't let you put two NICs on the same network, but
Linux and other *nix systems will let you do so (BSD flavors for example.)

I'm 99.9% sure that you can't on any of the Windows OSes though.

WTH:)
 
P

pigeonrandle

WTH,
Thanks again. I'm hoping i will only have to have the server running on
windows machines, but know that at some point i will have to 'learn
linux' to expand my market. Happy happy joy joy :blush:P

Cheers,
James.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top