Get IP address in a console application

前端 未结 6 1904
醉酒成梦
醉酒成梦 2021-02-12 22:35

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

6条回答
  •  被撕碎了的回忆
    2021-02-12 22:53

    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.

提交回复
热议问题