{"id":472,"date":"2007-02-27T14:44:05","date_gmt":"2007-02-27T14:44:05","guid":{"rendered":"http:\/\/fanhaijun.com\/?p=472"},"modified":"2007-02-27T14:44:05","modified_gmt":"2007-02-27T14:44:05","slug":"asp%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9c%9f%e5%ae%9eip%e5%9c%b0%e5%9d%80","status":"publish","type":"post","link":"https:\/\/fanhaijun.com\/?p=472","title":{"rendered":"ASP\u5982\u4f55\u83b7\u53d6\u5ba2\u6237\u7aef\u771f\u5b9eIP\u5730\u5740"},"content":{"rendered":"<p>\u5728ASP\u4e2d\u4f7f\u7528&nbsp;Request.ServerVariables(&quot;REMOTE_ADDR&quot;)&nbsp;\u6765\u53d6\u5f97\u5ba2\u6237\u7aef\u7684IP\u5730\u5740\uff0c\u4f46\u5982\u679c\u5ba2\u6237\u7aef\u662f\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668\u6765\u8bbf\u95ee\uff0c\u90a3\u53d6\u5230\u7684\u5c31\u662f\u4ee3\u7406\u670d\u52a1\u5668\u7684IP\u5730\u5740\uff0c\u800c\u4e0d\u662f\u771f\u6b63\u7684\u5ba2\u6237\u7aefIP\u5730\u5740\u3002\u8981\u60f3\u900f\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u53d6\u5f97\u5ba2\u6237\u7aef\u7684\u771f\u5b9eIP\u5730\u5740\uff0c\u5c31\u8981\u4f7f\u7528&nbsp;Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;\u6765\u8bfb\u53d6\u3002\u4e0d\u8fc7\u8981\u6ce8\u610f\u7684\u4e8b\uff0c\u5e76\u4e0d\u662f\u6bcf\u4e2a\u4ee3\u7406\u670d\u52a1\u5668\u90fd\u80fd\u7528&nbsp;Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;\u6765\u8bfb\u53d6\u5ba2\u6237\u7aef\u7684\u771f\u5b9e&nbsp;IP\uff0c\u6709\u4e9b\u7528\u6b64\u65b9\u6cd5\u8bfb\u53d6\u5230\u7684\u4ecd\u7136\u662f\u4ee3\u7406\u670d\u52a1\u5668\u7684IP\u3002\u8fd8\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a\u5982\u679c\u5ba2\u6237\u7aef\u6ca1\u6709\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\u6765\u8bbf\u95ee\uff0c\u90a3\u4e48\u7528&nbsp;Request.ServerVariables&nbsp;(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;\u53d6\u5230\u7684\u503c\u5c06\u662f\u7a7a\u7684\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8981\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u53ef\u4ee5\u8fd9\u6837\u5904\u7406\uff1a&nbsp;<br \/>&#8230;&#8230;&nbsp;<br \/>userip&nbsp;=&nbsp;Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;<br \/>If&nbsp;userip&nbsp;=&nbsp;&quot;&quot;&nbsp;Then&nbsp;userip&nbsp;=&nbsp;Request.ServerVariables(&quot;REMOTE_ADDR&quot;)&nbsp;<br \/>&#8230;&#8230;&nbsp;<\/p>\n<p>\u5373\uff1a\u5982\u679c\u5ba2\u6237\u7aef\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5219\u53d6&nbsp;HTTP_X_FORWARDED_FOR&nbsp;\u7684\u503c\uff0c\u5982\u679c\u6ca1\u901a\u8fc7\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5c31\u53d6&nbsp;REMOTE_ADDR&nbsp;\u7684\u503c\u3002&nbsp;<\/p>\n<p>&#39;\u901a\u7528\u51fd\u6570\uff1a\u5982\u679c\u4e0d\u80fd\u53d6\u5ba2\u6237\u7aef\u771f\u5b9eIP\uff0c\u5c31\u4f1a\u53d6\u5ba2\u6237\u7aef\u7684\u4ee3\u7406IP&nbsp;<br \/>Private&nbsp;Function&nbsp;getIP()&nbsp;<br \/>Dim&nbsp;strIPAddr&nbsp;<br \/>If&nbsp;Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;=&nbsp;&quot;&quot;&nbsp;OR&nbsp;InStr(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;&quot;unknown&quot;)&nbsp;&gt;&nbsp;0&nbsp;Then&nbsp;<br \/>strIPAddr&nbsp;=&nbsp;Request.ServerVariables(&quot;REMOTE_ADDR&quot;)&nbsp;<br \/>ElseIf&nbsp;InStr(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;&quot;,&quot;)&nbsp;&gt;&nbsp;0&nbsp;Then&nbsp;<br \/>strIPAddr&nbsp;=&nbsp;Mid(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;1,&nbsp;InStr(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;&quot;,&quot;)-1)&nbsp;<br \/>ElseIf&nbsp;InStr(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;&quot;;&quot;)&nbsp;&gt;&nbsp;0&nbsp;Then&nbsp;<br \/>strIPAddr&nbsp;=&nbsp;Mid(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;1,&nbsp;InStr(Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;),&nbsp;&quot;;&quot;)-1)&nbsp;<br \/>Else&nbsp;<br \/>strIPAddr&nbsp;=&nbsp;Request.ServerVariables(&quot;HTTP_X_FORWARDED_FOR&quot;)&nbsp;<br \/>End&nbsp;If&nbsp;<br \/>getIP&nbsp;=&nbsp;Trim(Mid(strIPAddr,&nbsp;1,&nbsp;30))&nbsp;<br \/>End&nbsp;Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728ASP\u4e2d\u4f7f\u7528&nbsp;Request.ServerVar&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[101],"tags":[],"class_list":["post-472","post","type-post","status-publish","format-standard","hentry","category-college-life"],"_links":{"self":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":0,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}