Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an app using TCP in c#. In which there will be one server and other will be clients. Every time when clients need to connect to server,they will require server ip address and port on which it is listening. Is there any way to make that ip static ?
To solve this problem , i was thinking that mac address will be constant , so if we is there any way to get ip address from the ma address, then my problem will solve.
Posted
Comments
n.podbielski 5-Nov-12 3:07am    
So you want to create server that have no IP address? What for? That what are IP addresses are for, so machines can communicate. It is like you would try to call someone without knowing phone number.
You should instead configure your network correctly.
footballpardeep 5-Nov-12 6:19am    
Nopes, server will have ip address, my problem was that every time the server will have new ip address, i want that to be constatnt.

1 solution

You can get the mac addresses and IP addresses together - have a look at this: Retrieving IP and MAC addresses for a LAN[^]

But that is a very clumsy solution.

Can I suggest that either they access via the PC name, or get the IP from the PC name? The latter is really simple:
C#
IPHostEntry host = Dns.GetHostByName("ANAS");
IPAddress ipaddr = host.AddressList[0];
That way, it's not tied to hardware - which can break, it's not tied to a specific machine - which can be replaced. You don't need to change software, just set the appropriate PC Id.
 
Share this answer
 
Comments
footballpardeep 5-Nov-12 6:20am    
Will it work on internet too, clients and sever are on internet.
OriginalGriff 5-Nov-12 7:09am    
No, you can't see client IP or MAC from the server (you get the IP of the router, not the client) or the server MAC from the client.

Static IP addresses are available - talk to whoever is hosting the server as they can probably provide it, but normally charge extra fro the service.
I would use the www name though - and let the normal internet DNS do the translation.
footballpardeep 5-Nov-12 8:54am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900