c# - User IP Address , Using Proxy or Not , Some Help -
c# - User IP Address , Using Proxy or Not , Some Help -
please see below codes :
private string getuseripaddress() { string user_ipaddress = string.empty; string user_ipaddressrange = request.servervariables["http_x_forwarded_for"]; if (string.isnullorempty(user_ipaddressrange))//without proxy detection { user_ipaddress = request.servervariables["remote_addr"]; //or //client_ipaddress = request.userhostaddress; //or //user_ipaddress = request.servervariables["remote_host"]; } else////with proxy detection { string[] splitter = { "," }; string[] ip_array = user_ipaddressrange.split(splitter, system.stringsplitoptions.none); int latestitem = ip_array.length - 1; user_ipaddress = ip_array[latestitem - 1]; //user_ipaddress = ip_array[0]; } homecoming user_ipaddress; } in case of : 1-
user_ipaddress = request.servervariables["remote_addr"]; and client_ipaddress = request.userhostaddress; and user_ipaddress = request.servervariables["remote_host"]; lower or middle line alternate other lines? woulld please give explain these lines? differences ?
2- user_ipaddress = ip_array[latestitem - 1]; and user_ipaddress = ip_array[0];
which line should utilize ? please give explain these lines?
thanks in advance
i don't know class chances request.userhostaddress alias request.servervariables["remote_addr"]. remote_host hostname in cases ipaddress.
format of x-forwarded-for client1, proxy1, proxy2. want sec one. user_ipaddress = ip_array[0];
just remember "since easy forge x-forwarded-for field given info should used care."
c# asp.net proxy ip-address
Comments
Post a Comment