I am looking to figure out what my IP address is from a console application.
I am used to a web application by using the Request.ServerVariables
collection and/or Request.UserHostAddress
.
How can this be done in a console app?
I am looking to figure out what my IP address is from a console application.
I am used to a web application by using the Request.ServerVariables
collection and/or Request.UserHostAddress
.
How can this be done in a console app?
System.Net.Dns.GetHostAddresses() should do it.
The System.Net namespace is your friend here. In particular, APIs such as DNS.GetHostByName.
However, any given machine may have multiple IP addresses (multiple NICs, IPv4 and IPv6 etc) so it's not quite as simple a question as you pose.
IPAddress[] addresslist = Dns.GetHostAddresses(Dns.GetHostName());
Try this:
The easiest way to do this is as follows:
source : http://www.codeproject.com/KB/cs/network.aspx