How to catch the IP address of the system - C#
I have faced this problem when I need to catch the webbrwser control's ip address in a .Net desktop application.
you have to import below namespaces for this code.
using System.Diagnostics;
using System.Net;
Then you paste below code to your code.
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
string ipadd = addr[0].ToString();
MessageBox.Show(addr[1].ToString()); // I have used a message box to check the ip address
Happy coding then. Good luck.
you have to import below namespaces for this code.
using System.Diagnostics;
using System.Net;
Then you paste below code to your code.
string strHostName = Dns.GetHostName();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
string ipadd = addr[0].ToString();
MessageBox.Show(addr[1].ToString()); // I have used a message box to check the ip address
Happy coding then. Good luck.
Comments
Post a Comment