IP难题,高分求教!顶者有分!

soho00222 2003-09-19 09:08:18
<%
userip = Request.ServerVariables("REMOTE_ADDR")
Response.Write userip
%>
如上代码,获得客户端IP,我都通过外网网址访问,为什么在别人服务器上我可以看到我正确的IP地址218.17.221.199,在我自已服务器上,同样的代码,无论是谁访问看到的IP都是172.16.100.10,高分求助!

这段文章可能写出我的问题,但我看不太懂!
http://www.csdn.net/develop/read_article.asp?id=19468
下面的贴子和我的问题差不多
http://expert.csdn.net/Expert/topic/2265/2265906.xml?temp=1.314944E-02
...全文
59 41 打赏 收藏 转发到动态 举报
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
soho00222 2003-09-19
  • 打赏
  • 举报
回复
superdullwolf(超级大笨狼)
你写的是什么??
超级大笨狼 2003-09-19
  • 打赏
  • 举报
回复
REMOTE_ADDR T
he IP address of the remote host making the request.

REMOTE_HOST
The name of the host making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.

REMOTE_USER
Unmapped user-name string sent in by the User. This is the name that is really sent by the user as opposed to the ones that are modified by any authentication filter installed on the server.

REQUEST_METHOD
The method used to make the request. For HTTP, this is GET, HEAD, POST, and so on.
超级大笨狼 2003-09-19
  • 打赏
  • 举报
回复
ServerVariables
The ServerVariables collection retrieves the values of predetermined environment variables.

Syntax
Request.ServerVariables (server environment variable)

Parameters
server environment variable
Specifies the name of the server environment variable to retrieve. It can be one of the following values. Variable Description
ALL_HTTP All HTTP headers sent by the client.
ALL_RAW Retrieves all headers in the raw-form. The difference between ALL_RAW and ALL_HTTP is that ALL_HTTP places an HTTP_ prefix before the header name and the header-name is always capitalized. In ALL_RAW the header name and values appear as they are sent by the client.
APPL_MD_PATH Retrieves the metabase path for the (WAM) Application for the ISAPI DLL.
APPL_PHYSICAL_PATH Retrieves the physical path corresponding to the metabase path. IIS converts the APPL_MD_PATH to the physical (directory) path to return this value.
AUTH_PASSWORD The value entered in the client's authentication dialog. This variable is only available if Basic authentication is used.
AUTH_TYPE The authentication method that the server uses to validate users when they attempt to access a protected script.
AUTH_USER Raw authenticated user name.
CERT_COOKIE Unique ID for client certificate, Returned as a string. Can be used as a signature for the whole client certificate.
CERT_FLAGS bit0 is set to 1 if the client certificate is present.
bit1 is set to 1 if the Certifying Authority of the client certificate is invalid (not in the list of recognized CA on the server).

CERT_ISSUER Issuer field of the client certificate (O=MS, OU=IAS, CN=user name, C=USA).
CERT_KEYSIZE Number of bits in Secure Sockets Layer connection key size. For example, 128.
CERT_SECRETKEYSIZE Number of bits in server certificate private key. For example, e.g. 1024.
CERT_SERIALNUMBER Serial number field of the client certificate.
CERT_SERVER_ISSUER Issuer field of the server certificate.
CERT_SERVER_SUBJECT Subject field of the server certificate.
CERT_SUBJECT Subject field of the client certificate.
CONTENT_LENGTH The length of the content as given by the client.
CONTENT_TYPE The data type of the content. Used with queries that have attached information, such as the HTTP queries GET, POST, and PUT.
GATEWAY_INTERFACE The revision of the CGI specification used by the server. The format is CGI/revision.
HTTP_<HeaderName> The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by HTTP_ in order for the ServerVariables collection to retrieve its value.
Note The server interprets any underscore (_) characters in HeaderName as dashes in the actual header. For example if you specify HTTP_MY_HEADER, the server searches for a header sent as MY-HEADER.

HTTPS Returns ON if the request came in through secure channel (SSL) or it returns OFF if the request is for a non-secure channel.
HTTPS_KEYSIZE Number of bits in Secure Sockets Layer connection key size. For example, 128.
HTTPS_SECRETKEYSIZE Number of bits in server certificate private key. For example, 1024.
HTTPS_SERVER_ISSUER Issuer field of the server certificate.
HTTPS_SERVER_SUBJECT Subject field of the server certificate.
INSTANCE_ID The ID for the IIS instance in textual format. If the instance ID is 1, it appears as a string. You can use this variable to retrieve the ID of the Web-server instance (in the metabase) to which the request belongs.
INSTANCE_META_PATH The metabase path for the instance of IIS that responds to the request.
LOCAL_ADDR Returns the Server Address on which the request came in. This is important on multi-homed machines where there can be multiple IP addresses bound to a machine and you want to find out which address the request used.
LOGON_USER The Windows NT® account that the user is logged into.
PATH_INFO Extra path information as given by the client. You can access scripts by using their virtual path and the PATH_INFO server variable. If this information comes from a URL, it is decoded by the server before it is passed to the CGI script.
PATH_TRANSLATED A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping.
QUERY_STRING Query information stored in the string following the question mark (?) in the HTTP request.
REMOTE_ADDR The IP address of the remote host making the request.
REMOTE_HOST The name of the host making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this empty.
REMOTE_USER Unmapped user-name string sent in by the User. This is the name that is really sent by the user as opposed to the ones that are modified by any authentication filter installed on the server.
REQUEST_METHOD The method used to make the request. For HTTP, this is GET, HEAD, POST, and so on.
SCRIPT_NAME A virtual path to the script being executed. This is used for self-referencing URLs.
SERVER_NAME The server's host name, DNS alias, or IP address as it would appear in self-referencing URLs.
SERVER_PORT The port number to which the request was sent.
SERVER_PORT_SECURE A string that contains either 0 or 1. If the request is being handled on the secure port, then this will be 1. Otherwise, it will be 0.
SERVER_PROTOCOL The name and revision of the request information protocol. The format is protocol/revision.
SERVER_SOFTWARE The name and version of the server software that answers the request and runs the gateway. The format is name/version.
URL Gives the base portion of the URL.


Remarks
If a client sends a header other than those specified in the preceding table, you can retrieve the value of that header by prefixing the header name with HTTP_ in the call to Request.ServerVariables. For example, if the client sent this header

SomeNewHeader:SomeNewValue

you could retrieve SomeNewValue by using the following syntax

<% Request.ServerVariables("HTTP_SomeNewHeader") %>

You can use an iterator to loop through each server variable name. For example, the following script prints out all of the server variables in a table.

<TABLE>
<TR><TD><B>Server Variable</B></TD><TD><B>Value</B></TD></TR>
<% For Each name In Request.ServerVariables %>
<TR><TD> <%= name %> </TD><TD> <%= Request.ServerVariables(name) %> </TD></TR>
</TABLE>
<% Next %>

Example
The following example uses the Request object to display several server variables.

<HTML>
<!-- This example displays the content of several ServerVariables. -->
ALL_HTTP server variable =
<%= Request.ServerVariables("ALL_HTTP") %> <BR>
CONTENT_LENGTH server variable =
<%= Request.ServerVariables("CONTENT_LENGTH") %> <BR>
CONTENT_TYPE server variable =
<%= Request.ServerVariables("CONTENT_TYPE") %> <BR>
QUERY_STRING server variable =
<%= Request.ServerVariables("QUERY_STRING") %> <BR>
SERVER_SOFTWARE server variable =
<%= Request.ServerVariables("SERVER_SOFTWARE") %> <BR>
</HTML>

The next example uses the ServerVariables collection to insert the name of the server into a hyperlink.

<A HREF = "http://<%= Request.ServerVariables("SERVER_NAME") %>
/scripts/MyPage.asp">Link to MyPage.asp</A>

Applies To
Request Object

See Also
ClientCertificate, Cookies, Form, QueryString


postform999 2003-09-19
  • 打赏
  • 举报
回复
看来还是因为内网的关系
lang11zi 2003-09-19
  • 打赏
  • 举报
回复
重新启动计算机~~~~~~~~~~```


再用外网登陆,我遇到过
soho00222 2003-09-19
  • 打赏
  • 举报
回复
TT
zxmout 2003-09-19
  • 打赏
  • 举报
回复
给我地址我看看!
soho00222 2003-09-19
  • 打赏
  • 举报
回复
userip = Request.ServerVariables("REMOTE_ADDR")
这样的命令无论是内网,还是外网访问得到的IP都是172.16.100.10
我如何区分??
zxmout 2003-09-19
  • 打赏
  • 举报
回复
你可以把它的ip写进数据库呀!
soho00222 2003-09-19
  • 打赏
  • 举报
回复
那我如何判断来访者是来自内网还是外网?
zxmout 2003-09-19
  • 打赏
  • 举报
回复
内部网络解析的肯定是一样的。
对外的话就正常了,应为内部网络只有一个出口。
soho00222 2003-09-19
  • 打赏
  • 举报
回复
Dim userip,userip2
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
userip2 = Request.ServerVariables("REMOTE_ADDR")
if userip = "" then
response.write "您的真实IP 是:"&userip2&","
else
response.write "您的真实IP 是:"&userip&","
end if

您的真实IP 是:218.17.221.199!可以取得外部IP了,但问题又来了!
有些内网的东东,要在外网看不到!如何做到!




Suckbin 2003-09-19
  • 打赏
  • 举报
回复

简单一点:

外部数据包到达你的机器是通过172.16.100.10这台机器的.
所以数据来源就变成了来自于172.16.100.10的数据.

Suckbin 2003-09-19
  • 打赏
  • 举报
回复


172.16.100.10是C类的一个专用IP(PRIVATE IP).
是用于组成局领网而留下来的IP.详细的内容可以用"PRIVATE IP"关键字搜索到.

172.16.100.10可能是你们内网的网关地址(GATEWAY IP).
内网和外网是通过网关来相连的.
所有来字外网的数据包在到达你的服务器之前都要通过GATEWAY才能到达你的服务器.
从而原来来自外网的数据包的IP层报头中含有数据来源(也就是IP)的部分变成GATEWAY的
IP是很普遍的事情.(IP变不变的关键在于程序)

你在你的服务器的DOS窗口中输入:IPCONFIG来看看.
估计列出来的GATEWAY IP有可能就是172.16.100.10~~~~~~~~~~~~~

以上只不过是出现你说的问题的一种猜测而已.
如果更正确的说的话,172.16.100.10是你的服务器和外网连接时必须通过的机器的IP~~~~
soho00222 2003-09-19
  • 打赏
  • 举报
回复
当然这个网址在外部网也是可以访问的,不过是解析到我们的公网IP了!!
soho00222 2003-09-19
  • 打赏
  • 举报
回复
我刚才问了,我们的网址在内部访问时没有出去,而是直接解析在内部!
也就是我们访问网站,不用上INTERNET网出去,再回来访问我们的服务器,而是直接解析过来了!在这种情况下,userip = Request.ServerVariables("REMOTE_ADDR")得到的是哪个IP呢?
dippergao 2003-09-19
  • 打赏
  • 举报
回复
把大家的建议每个都亲自调试调试
就会有结果了哦
zxmout 2003-09-19
  • 打赏
  • 举报
回复
我测试了没有问题呀!很郁闷,呵呵~~~
hubinasm 2003-09-19
  • 打赏
  • 举报
回复
Jaron(唐伯虎点蚊香) 已经把问题给你解答了啊。还问???
NetBoy 2003-09-19
  • 打赏
  • 举报
回复
怪了,GZ,
加载更多回复(21)

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧