.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Network >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Find the ComputerName and IPAddress using SocketProgramming?

Posted By:Syed Shakeer Hussain       Posted Date: August 15, 2010    Points: 10    Category: Network    URL: http://www.dotnetspark.com  

The Following helps you for finding the ComputerName and IPAdress of a Computer
 

using System;
using System.Net;
class ShowIP{
    public static void Main(string[] args){
        string name = (args.Length < 1) ? Dns.GetHostName() : args[0];
        try{
            IPAddress[] addrs = Dns.Resolve(name).AddressList;
            foreach(IPAddress addr in addrs) 
                Console.WriteLine("{0} {1}",name,addr);
        }catch(Exception e){
            Console.WriteLine(e.Message);
        }
    }
}
it displays the name and IP address of the local machine.

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend