1. 程式人生 > >c#中獲取伺服器IP,客戶端IP以及Request.ServerVariables詳細說明

c#中獲取伺服器IP,客戶端IP以及Request.ServerVariables詳細說明

客戶端ip:
Request.ServerVariables.Get(“Remote_Addr”).ToString();
客戶端主機名:
Request.ServerVariables.Get(“Remote_Host”).ToString();
客戶端瀏覽器IE:
Request.Browser.Browser;
客戶端瀏覽器 版本號:
Request.Browser.MajorVersion;//
客戶端作業系統:
Request.Browser.Platform;
伺服器ip:
Request.ServerVariables.Get(“Local_Addr”).ToString();
伺服器名:
Request.ServerVariables.Get(“Server_Name”).ToString();
如果你想進一步瞭解ServerVariables,可以用
foreach(String o in Request.ServerVariables){
Response.Write(o+”=”+Request.ServerVariables[o]+”
”);
}
獲取客戶端IP方法
public string GetIP()
{
string uip = “”;
if (HttpContext.Current.Request.ServerVariables[“HTTP_VIA”] != null)
{
uip = HttpContext.Current.Request.ServerVariables[“HTTP_X_FORWARDED_FOR”].ToString();
}
else
{
uip = HttpContext.Current.Request.ServerVariables[“REMOTE_ADDR”].ToString();
}
return uip;
}

C# ServerVariables引數說明
Request.ServerVariables[“Url”]
返回伺服器地址
Request.ServerVariables[“Path_Info”]
客戶端提供的路徑資訊
Request.ServerVariables[“Appl_Physical_Path”]
與應用程式元資料庫路徑相應的物理路徑
Request.ServerVariables[“Path_Translated”]
通過由虛擬至物理的對映後得到的路徑
Request.ServerVariables[“Script_Name”]
執行指令碼的名稱
Request.ServerVariables[“Query_String”]
查詢字串內容
Request.ServerVariables[“Http_Referer”]
請求的字串內容
Request.ServerVariables[“Server_Port”]
接受請求的伺服器埠號
Request.ServerVariables[“Remote_Addr”]
發出請求的遠端主機的IP地址
Request.ServerVariables[“Remote_Host”]
發出請求的遠端主機名稱
Request.ServerVariables[“Local_Addr”]
返回接受請求的伺服器地址
Request.ServerVariables[“Http_Host”]
返回伺服器地址
Request.ServerVariables[“Server_Name”]
伺服器的主機名、DNS地址或IP地址
Request.ServerVariables[“Request_Method”]
提出請求的方法比如GET、HEAD、POST等等
Request.ServerVariables[“Server_Port_Secure”]
如果接受請求的伺服器埠為安全埠時,則為1,否則為0
Request.ServerVariables[“Server_Protocol”]
伺服器使用的協議的名稱和版本
Request.ServerVariables[“Server_Software”]
應答請求並執行閘道器的伺服器軟體的名稱和版本
Request.ServerVariables[“All_Http”]
客戶端傳送的所有HTTP標頭,字首HTTP_
Request.ServerVariables[“All_Raw”]
客戶端傳送的所有HTTP標頭,其結果和客戶端傳送時一樣,沒有字首HTTP_
Request.ServerVariables[“Appl_MD_Path”]
應用程式的元資料庫路徑
Request.ServerVariables[“Content_Length”]
客戶端發出內容的長度
Request.ServerVariables[“Https”]
如果請求穿過安全通道(SSL),則返回ON如果請求來自非安全通道,則返回OFF
Request.ServerVariables[“Instance_ID”]
IIS例項的ID號
Request.ServerVariables[“Instance_Meta_Path”]
響應請求的IIS例項的元資料庫路徑
Request.ServerVariables[“Http_Accept_Encoding”]
返回內容如:gzip,deflate
Request.ServerVariables[“Http_Accept_Language”]
返回內容如:en-us
Request.ServerVariables[“Http_Connection”]
返回內容:Keep-Alive
Request.ServerVariables[“Http_Cookie”]
返回內容如:nVisiT%
2DYum=125;ASPSESSIONIDCARTQTRA=FDOBFFABJGOECBBKHKGPFIJI;ASPSESSIONIDCAQQTSRB=LKJJPLABABILLPCOGJGAMKAM;ASPSESSIONIDACRRSSRA=DK
HHHFBBJOJCCONPPHLKGHPB
Request.ServerVariables[“Http_User_Agent”]
返回內容:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)
Request.ServerVariables[“Https_Keysize”]
安全套接字層連線關鍵字的位數,如128
Request.ServerVariables[“Https_Secretkeysize”]
伺服器驗證私人關鍵字的位數如1024
Request.ServerVariables[“Https_Server_Issuer”]
伺服器證書的發行者欄位
Request.ServerVariables[“Https_Server_Subject”]
伺服器證書的主題欄位
Request.ServerVariables[“Auth_Password”]
當使用基本驗證模式時,客戶在密碼對話方塊中輸入的密碼
Request.ServerVariables[“Auth_Type”]
是使用者訪問受保護的指令碼時,伺服器用於檢驗使用者的驗證方法
Request.ServerVariables[“Auth_User”]
代證的使用者名稱
Request.ServerVariables[“Cert_Cookie”]
唯一的客戶證書ID號
Request.ServerVariables[“Cert_Flag”]
客戶證書標誌,如有客戶端證書,則bit0為0如果客戶端證書驗證無效,bit1被設定為1
Request.ServerVariables[“Cert_Issuer”]
使用者證書中的發行者欄位
Request.ServerVariables[“Cert_Keysize”]
安全套接字層連線關鍵字的位數,如128
Request.ServerVariables[“Cert_Secretkeysize”]
伺服器驗證私人關鍵字的位數如1024
Request.ServerVariables[“Cert_Serialnumber”]
客戶證書的序列號欄位
Request.ServerVariables[“Cert_Server_Issuer”]
伺服器證書的發行者欄位
Request.ServerVariables[“Cert_Server_Subject”]
伺服器證書的主題欄位
Request.ServerVariables[“Cert_Subject”]
客戶端證書的主題欄位
Request.ServerVariables[“Content_Type”]
客戶傳送的form內容或HTTPPUT的資料型別
Request.ServerVariables[“HTTP_X_FORWARDED_FOR”]
可以獲得位於代理(閘道器)後面的直接IP,當然必須這個代理支援

一些被隱藏起來的Request.ServerVariables引數:
Request.ServerVariables[“NUMBER_OF_PROCESSORS”]
Request.ServerVariables[“OS”]
Request.ServerVariables[“WINDIR”]
Request.ServerVariables[“TEMP”]
Request.ServerVariables[“TMP”]
Request.ServerVariables[“ComSpec”]
Request.ServerVariables[“Os2LibPath”]
Request.ServerVariables[“Path”]
Request.ServerVariables[“PATHEXT”]
Request.ServerVariables[“PROCESSOR_ARCHITECTURE”]
Request.ServerVariables[“PROCESSOR_IDENTIFIER”]
Request.ServerVariables[“PROCESSOR_LEVEL”]
Request.ServerVariables[“PROCESSOR_REVISION”]

本機ip:<%=request.servervariables[“remote_addr”]%>

伺服器名:<%=Request.ServerVariables[“SERVER_NAME”]%>

伺服器IP:<%=Request.ServerVariables[“LOCAL_ADDR”]%>

伺服器埠:<%=Request.ServerVariables[“SERVER_PORT”]%>

伺服器時間:<%=now%>

IIS版本:<%=Request.ServerVariables[“SERVER_SOFTWARE”]%>

指令碼超時時間:<%=Server.ScriptTimeout%>

本檔案路徑:<%=server.mappath(Request.ServerVariables[“SCRIPT_NAME”])%>

伺服器CPU數量:<%=Request.ServerVariables[“NUMBER_OF_PROCESSORS”]%>

伺服器解譯引擎:<%=ScriptEngine & “/”& ScriptEngineMajorVersion&”.”&ScriptEngineMinorVersion&”.”& ScriptEngineBuildVersion %>

伺服器作業系統:<%=Request.ServerVariables[“OS”]%>

支援的檔案型別:<%=Request.ServerVariables[“HTTP_Accept”]%>

訪問的檔案路徑:<%=Request.ServerVariables[“HTTP_url”]%>

使用者代理的資訊:<%=Request.ServerVariables[“HTTP_USER_AGENT”]%>

Request.ServerVariables變數意義. http代理相關知識
Request.ServerVariables[“HTTP_VIA”]———可以獲得使用者內部的ip
Request.ServerVariables[“HTTP_X_FORWARDED_FOR”]———可以知道代理伺服器的伺服器名以及埠
Request.ServerVariables[“REMOTE_ADDR”]– 發出請求的遠端主機的 IP 地址。
http代理相關知識
關鍵就在HTTP_X_FORWARDED_FOR
使用不同種類代理伺服器,上面的資訊會有所不同:
一、沒有使用代理伺服器的情況:
REMOTE_ADDR = 您的 IP
HTTP_VIA = 沒數值或不顯示
HTTP_X_FORWARDED_FOR = 沒數值或不顯示
二、使用透明代理伺服器的情況:Transparent Proxies
REMOTE_ADDR = 代理伺服器 IP
HTTP_VIA = 代理伺服器 IP
HTTP_X_FORWARDED_FOR = 您的真實 IP
這類代理伺服器還是將您的資訊轉發給您的訪問物件,無法達到隱藏真實身份的目的。
三、使用普通匿名代理伺服器的情況:Anonymous Proxies
REMOTE_ADDR = 代理伺服器 IP
HTTP_VIA =

相關推薦

c#獲取伺服器IP客戶IP以及Request.ServerVariables詳細說明

客戶端ip: Request.ServerVariables.Get(“Remote_Addr”).ToString(); 客戶端主機名: Request.ServerVariables.Get(“Remote_Host”).ToString();

C# 之 獲取伺服器IP客戶IP以及其它

1、獲取客戶端IP:Request.ServerVariables.Get("Remote_Addr").ToString(); 2、獲取客戶端主機名:Request.ServerVariables.Get("Remote_Host").ToString(); 3、客戶端瀏覽器:Request.

C# 之 獲取服務器IP客戶IP以及其它

output ipaddress ons use variables 例子 mac地址 user nag 本文主要是從網絡上搜索的文章進行參考,也是提供一個大概的方向和思路吧。當然如果有能用的代碼,可直接復制過去根據自己的情況修改和使用。 一、思路(主要用於局域網內

獲取服務器IP客戶IP

進程 獲取 () base accep roc eight 可能 php_sapi 客戶端IP相關的變量 1. $_SERVER[‘REMOTE_ADDR‘]; 客戶端IP,有可能是用戶的IP,也有可能是代理的IP。 2. $_SERVER[‘HTTP_CLIENT_IP

請求Requst獲取訪問請求的客戶IP

請求Requst中獲取訪問請求的客戶端IP 在JSP裡,獲取客戶端的IP地址的方法是:request.getRemoteAddr(),這種方法在大部分情況下都是有效的。但是在通過了Apache,Squid,nginx等反向代理軟體就不能獲取到客戶端的真實IP地址了。 如果使

伺服器獲取客戶IP客戶IP變化

1.服務端獲取客戶端請求的IP等資訊request = javax.servlet.http.HttpServletRequest request.getRemoteAddr()獲取客戶端請求IP地址 request.getRemotePort() 獲取客戶端請求埠 req

SVN伺服器更換IP客戶重新定位

svn伺服器更換ip,後客戶端需要重新定位,操作如下: 1.找到你的專案檔案所在的根目錄,右鍵點選空白地方,彈出選單 TortoiseSVN-->Relocate  點選Relocate ,彈出重新遷移視窗。   修改你的svn版本控制元件器地址,也就

SVN服務器更換IP客戶重新定位

找到你 ima 客戶 logs ges 技術分享 images 找到 mage ---恢復內容開始--- svn服務器更換ip,後客戶端需要重新定位,操作如下: 1.找到你的項目文件所在的根目錄,右鍵點擊空白地方,彈出菜單 TortoiseSVN-->Relocate

Java獲取服務器IP客戶IP

audio sta ignorecas als style param servlet controls cal 服務器IP: String addr = InetAddress.getLocalHost().getHostAddress(); 說明:很明顯上面

Django 如何獲取真實遠程客戶IP

jpg 可用 base 分享 ddr 技術 自定義 客戶 get 問題簡述 我們知道HttpRequest.META字典包含所有HTTP頭部信息(可用的頭部信息取決於客戶端和服務器)。一般情況下,HttpRequest.META.get(‘REMOTE_ADDR‘)一句代碼

linux centOs安裝好資料庫客戶用plsql連線oracle

  原創作品,轉載請在文章顯眼位置註明出處:https://www.cnblogs.com/sunshine5683/p/10030375.html  首先,回顧上篇 CenOs7安裝oracle圖文詳細過程(02) ,安裝好oracle後再伺服器端使用sqlplu

Java獲取訪問使用者的客戶IP地址(適用於公網與區域網)

  /** * 獲取Ip地址,多級反向代理 * @param request * @return */ public static String getIpaddr(HttpServletRequest request){ String ipAddress = request.ge

C++ Socket 一個伺服器 多個客戶 (阻塞式)

服務端 ServerNet.h #pragma once #include <stdio.h> #include <winsock.h> #include<vector> #include<iterator>

C#獲取當前時間及處理時間(對時間進行加減)

1.獲取當前的時間,並將時間格式化成為字串   DateTime dt=Datetime.Now;   string str=dt.ToString();        //這是最直接的轉化方法   string str2=dt.ToString("yyy-MM-dd HH:mm:ss");2.獲取年、月、日

php獲取nginx代理後的客戶真實IP

一般來說,PHP獲取IP用的是$_SERVER[‘REMOTE_ADDR’],但是經過代理後,這個方式獲取到的是代理伺服器的ip,不符合要求!如果需要獲取真實IP該做什麼呢? 1.修改nginx配置:p

PHP獲取客戶IP地址服務器IP地址

客戶端 get sse spa gets static p地址 tip sta ============================================獲取客戶端IP==============================================

JAVA經過nginx反向代理獲取客戶ip獲取相關坐標等信息

IT urn 輸出 代理 nginx 高德 AD color javascrip 關於搜狐新浪ip庫查詢接口的使用 直接輸出訪客ip及所在城市: <script src="http://pv.sohu.com/cityjson?ie=utf-8" >&l

獲取nginx客戶IP地址 Java request獲取客戶ip各種apach,nginx等代理後依然正確

Java request獲取客戶端ip,各種apach,nginx等代理後依然正確 2017年02月22日 17:15:15 閱讀數:3268 在JSP,Java裡,獲取客戶端的IP地址的方法是:request.getRem

在ASP.NET Core 2.x獲取客戶IP地址

一、前言 大家也知道服務端請求時我們獲取的IP地址是包含在請求頭中,因此這也大大便利了IP的獲取。 在ASP.NET中,可以通過以下方式獲取客戶端的IP地址。 HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]

php獲取客戶ip地址或者伺服器ip地址

1.$_SERVER['REMOTE_ADDR'] 客戶端IP,有可能是使用者的IP,也可能是代理的IP。 2.$_SERVER['HTTP_CLIENT_IP'] 代理端的IP,可能存在可偽造。 3.$_SERVER['HTTP_X_FORWARDER_FOR'] 使用者是在哪個IP使用的代理,可