- 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.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Sakar SRPosted Jul 2, 2011, 12:49 AM
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