如何获取本地IP地址 [英] How to Get Local IP Address

查看:99
本文介绍了如何获取本地IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中获取LAN IP地址
通过编程方式
请不要建议
Request.servervariable ["ramote_addr"]

像这样的Dns.gethostname

How to get LAN IP address in asp.net
by programetically
plz do not suggest
Request.servervariable["ramote_addr"]
or
Dns.gethostname like this

推荐答案

尝试以下代码

try with following code

Request.Params["REMOTE_ADDR"];


您可以使用 Dns.GetHostAddresses [^ ]
You can use Dns.GetHostAddresses[^]
IPAddress[] ipList = Dns.GetHostAddresses(Dns.GetHostName());


尝试一下:

Try this :

System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].GetIPProperties().UnicastAddresses[0].Address



第一个索引是如果您有多个网卡,第二个索引是如果您在同一网卡上有多个IP地址.

另外,请检查此 http://www.csharp-examples.net/local-ip/ [ ^ ]

希望这会有所帮助.
一切顺利.



The first index is if you have multiple network cards and the second index is if you have multiple ip addresses on the same network card.

Also, check this http://www.csharp-examples.net/local-ip/[^]

Hope this helps.
All the best.


这篇关于如何获取本地IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆