如何获取应用程序服务器的IP地址

发布于 2024-08-28 18:18:42 字数 123 浏览 3 评论 0原文

我需要能够找到当前正在执行页面的服务器的 IP 地址。我有一些调用第三方站点的代码,并且必须传递一个特定的密钥,该密钥根据其所在的服务器而变化。 ColdFusion 中是否有 CGI 变量或某种方式来确定主机服务器的 IP 地址?

I need to be able to find the IP address of the server the page is currently executing on. I have some code that calls a third party site and has to pass a specific key that changes depending on which server it is on. Is there a CGI variable or some way in ColdFusion to determine what the IP address is of the host server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

星星的軌跡 2024-09-04 18:18:42

就像其他评论者概述的那样,如果您需要第三方网站看到的外部 IP,那么您可能应该使用他们推荐的外部方法。

但是,如果第三方以某种形式为您提供基于服务器看到的实际 IP 的访问权限,而不是他们看到的 IP,您可以使用

 <cfset cName = CreateObject("java", "java.net.InetAddress").getLocalHost().getHostAddress()>

 <cfdump var="#cName#">

Like the other commenters have outlined if you need the external IP as the third party site sees it then you probably should use the external approaches they recommend.

However if the third party is giving you access in some form that is based on an actual IP as the Server sees itself and not the IP as they see it you can use

 <cfset cName = CreateObject("java", "java.net.InetAddress").getLocalHost().getHostAddress()>

 <cfdump var="#cName#">
山川志 2024-09-04 18:18:42

您可以使用 CGI.LOCAL_ADDR 来确定服务器的 IP 地址(CFML 相当于 PHP 的 $_SERVER["SERVER_ADDR"])。它可以在使用 ColdFusion 或 Railo 的 IIS 和 Apache 上运行,前提是您不在代理后面,没有获取您的服务器 IP,并且只有一个 IP 分配给您的服务器(不确定会显示哪个 IP,如果有多个 IP)。

You can use CGI.LOCAL_ADDR to determine the IP-address of your server (CFML equivalent to PHP's $_SERVER["SERVER_ADDR"]). It works on IIS and Apache using ColdFusion or Railo, given you are not behind a Proxy, not natting your server IP and having only one IP assigned to your server (not sure which IP would be shown, if there are more than one).

a√萤火虫的光℡ 2024-09-04 18:18:42

程序无法查询其运行的主机并查看其 IP 是什么有两个原因:

  1. 它可能有多个 ip,并且如果不查看各种内核数据结构,您不太可能知道哪些 IP一个将用于给定的传出连接。

  2. 它可能会通过 NAT 防火墙或某种代理连接到外部世界,这样外部世界就会看到与您的盒子上配置的任何 IP 不同的 IP。

事实上,可能不止这两个,但这些是我想到的。

因此,最简单的方法是连接到公司网络之外的另一个盒子,看看它认为你拥有什么 IP。我使用在我的主机上运行的两行 CGI 脚本来检测我的家庭服务器当前拥有的 IP(这样我就可以检测到有线电视公司何时更改它)。

There are two reasons why a program can't query the host it's running on and see what its IP is:

  1. It might have multiple ips, and short of looking through all sorts of kernel data structures you're unlikely to know which one is going to be used for a given outgoing connection.

  2. It might connect to the outside world though a NAT firewall or some sort of proxy so that the outside world will see a different IP than any of the ones configured on your box.

Actually, there might be more than those two, but those are ones that have occurred to me.

Because of that, the simplest way is to connect to another box somewhere outside of your corporate network and see what IP it thinks you have. I use a two line CGI script running on my colo box to detect what IP my home server currently has (so I can detect when the cable company changes it).

趴在窗边数星星i 2024-09-04 18:18:42

最安全的方法是使用 WhatIsMyIP 之类的服务。如果服务器位于 NAT 之后,则操作系统不知道外部 IP 地址。

SO 中有很多与此相关的问题,例如,请参阅此处

The safest way will be to use a service like WhatIsMyIP. If the server is behind a NAT, then the OS has no knowledge of the external IP address.

There are many questions in SO regarding this, see here for example.

拒绝两难 2024-09-04 18:18:42
<cfhttp url="http://www.whatismyip.com/" result="myresult" resolveurl="yes">
<cfoutput>#myresult.filecontent#</cfoutput>
<cfhttp url="http://www.whatismyip.com/" result="myresult" resolveurl="yes">
<cfoutput>#myresult.filecontent#</cfoutput>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文