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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

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

 Subscribe to Code Snippets

Find an IP Address

Posted By:Akhil Raj       Posted Date: January 30, 2014    Points: 40    Category: Network    URL: http://www.dotnetspark.com  

This explains to find the client's ip address of the systsem using C#

There is some methods to find this. But i thing the easiest method is

string strHostName = Dns.GetHostName();
                IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
                string ip = "";
                foreach (IPAddress ipAddress in ipEntry.AddressList)
                    if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
                        ip = ipAddress.ToString();
To work this, you need to include the following namespaces
using System.Net;
using System.Net.Sockets;


Further Readings:


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