http://www.dotblogs.com.tw/mingstyle/archive/2013/03/09/96041.aspx
http://pbnpbnbkx.pixnet.net/blog/post/54098472-%E7%82%BA%E4%BD%95%E8%A6%81%E5%BE%9Easp%E5%8D%87%E7%B4%9A%E5%88%B0asp.net
VBNET修改電腦名稱
參考
ASP.NET 取得 Client端使用者相關資訊(AD, Local)
//取得對方的IP Adress
HttpContext.Current.Request.UserHostAddress;
Request.UserHostAddress.ToString()
//取得對方的主機名稱
System.Net.Dns.GetHostName();
//取得電腦現在的時間
DateTime.Now.ToString();
//取得目前這頁網址
Request.Url.ToString();
//AD Client端名稱 (若沒有windows登入驗證則沒有)
System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()
web.config 設定
IIS 設定
1. 將驗證方法內「啟用匿名存取」取消
2. 將驗證方法內「整合式Windows驗證」勾選
https://msdn.microsoft.com/zh-tw/library/system.web.httprequest.browser(v=vs.80).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
http://msdn.microsoft.com/zh-tw/library/system.web.httprequest.browser(VS.80).aspx
Request.UserHostAddress => 取IP值
Request.UserHostName => 取電腦名稱
設定 REMOTE_HOST 在 IIS 中執行反向 DNS 查閱
在伺服器DOS 命令列下
1. cd C:\Inetpub\Adminscripts
2. cscript adsutil.vbs set /w3svc/EnableReverseDNS "TRUE"
vb net
Dim ip As String
ip = HttpContext.Current.Request.UserHostAddress
Dim hostInfo As System.Net.IPHostEntry
hostInfo = System.Net.Dns.GetHostByAddress(ip)
Dim name As String
name = hostInfo.HostName
Response.Write(name)
=========================================================
您可以使用ASP的Request對象的方法ServerVariables方法得到客戶機的機器名,如下:
遠程客戶機名
一般情況下,考慮到網絡性能,Request.servervariables("REMOTE_HOST")返回客戶的IP地址。您可以改變IIS的metabase的設定,允許IIS根據客戶的IP地址查詢用戶的機器名。
您可以改變IIS的metabase的相關設定有兩種方法:
1.在Asp中用代碼設定
Dim oIIS
Dim vEnableRevDNS
Dim vDisableRevDNS
vEnableRevDNS = 1
vDisableRevDNS = 0
Set oIIS = GetObject("IIS://localhost/w3svc")
oIIS.Put "EnableReverseDNS", vEnableRevDNS
oIIS.SetInfo
Set oIIS = Nothing
2. 運行命令行:cscript C:\Inetpub\AdminScripts\adsutil.vbs set /w3svc/EnableReverseDNS "TRUE"
此時,Request.servervariables("REMOTE_HOST")返回客戶的機器名。
=============================================================
方法二:
strIP = Request.ServerVariables("REMOTE_ADDR")
strHost = Request.ServerVariables("REMOTE_HOST")
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & " 〉 d:\wwwtemp" & strIP & ".txt",0,true
sh.run "%comspec% /c ping -a " & strIP & " 〉 d:\wwwtemp" & strIP & "ping.txt",0,true
Set sh = nothing
'分析ping命令結果獲取計算機名
Function GetComputerName(strIP)
set fso=CreateObject("scripting.filesystemobject")
set ts=fso.opentextfile("d:\wwwtemp" & strIP & "ping.txt")
computername=null
do while not ts.AtEndOfStream
data = ucase(trim(ts.readline))
if instr(data,"[") then
computername=trim(split(data,"[")(0))
computername=trim(replace(computername,"PINGING",""))
exit do
end if
loop
GetComputerName=computername
End Function
'分析nbtstat命令結果獲取MAC地址
Function GetMACAddress(strIP)
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("d:\wwwtemp" & strIP & ".txt")
macaddress = null
Do While Not ts.AtEndOfStream
data = ucase(trim(ts.readline))
If instr(data,"MAC ADDRESS") Then
macaddress = trim(split(data,"=")(1))
Exit Do
End If
loop
GetMACAddress = macaddress
End Function