.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 >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

IP Address in C#.Net

Posted By:Sasi Prabhu       Posted Date: July 30, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Get the IP Address and Host Name in C#.Net
 



string IPAddress = "127.0.0.1";

// To Get IP Address
IPHostEntry IPHostEntryObject = Dns.GetHostEntry(IPAddress);
// To Get HostName
Console.WriteLine(IPHostEntryObject.HostName);



     

Further Readings:

Responses
Author: Ravi Ranjan Kumar         Company URL: http://www.dotnetspark.com
Posted Date: July 30, 2011

Its not returning an IP address. your code is only able to give HostName.
so Either Change your Code Snippet title or change your Code.

and as a suggestion I would like to say that you should mention
"using System.Net" namespace that will identify "IPHostEntry" otherwise an beginner OP can't get it in proper way.



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