1. 在asp.Net中專用屬性:
獲取服務器電腦名:page.server.manchinename
獲取用戶信息:page.user
獲取客戶端電腦名:page.request.userhostname
獲取客戶端電腦ip:page.request.userhostaddress
2. 在網絡編程中的通用方法:
獲取當前電腦名:static system.Net.dns.gethostname()
根據電腦名取出全部ip地址:static system.Net.dns.resolve(電腦名).addresslist
也可根據ip地址取出電腦名:static system.Net.dns.resolve(ip地址).hostname
3. 系統環境類的通用屬性:
當前電腦名:static system.environment.machinename
當前電腦所屬網域:static system.environment.userdomainname
當前電腦用戶:static system.environment.username
舉例子來說明:
using system.Net;
private void buttonip_click(object sender, system.eventargs e)
{
system.Net.ipaddress[] addresslist = dns.gethostbyname(dns.gethostname()).addresslist;
if (addresslist.length>1)
{
textlip.text = addresslist[0].tostring();
textsip.text = addresslist[1].tostring();
}
else
{
textlip.text = addresslist[0].tostring();
textsip.text = "沒有可用的連接";
}
}