- Step- open VS studio 2008/2010 ----Console Application
- First add network related Namespace like
Using System.Net;
And Using System.Net,NetworkInformation;
- And write follow code
{
string hostname = Dns.GetHostName();
Console.WriteLine(hostname);
IPAddress[] ipaddress = Dns.GetHostAddresses(hostname);
Console.WriteLine(ipaddress[1]);}
Above code is to find IP address of one system if you want communicate between two system throw IP address in LAN then use follow code
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(ipaddress[1], timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer size: {0}", reply.Buffer.Length);
}}
- Run this code and give command ping and checked whether communication is going or not.
How to find the IP address of one system
In This article we see how to find IP Address of one system,This is useful for Network programming Developer. so lets see step by step


Sakar SRPosted Jul 1, 2011, 8:49 PM EDT
Hi, I am using this method in my programming to control the user logging. It works fine when i am not in Net. But when i am in net, i get different IP address, when i log-in to my program. This happens in WIN 7. Is their a workaround to overcome this problem. Thank-U , have a nice day