【问题标题】:How do I find the IP address of a web site that is sending data by POST method to an asp.net web page?如何找到通过 POST 方法将数据发送到 asp.net 网页的网站的 IP 地址?
【发布时间】:2011-10-11 05:54:32
【问题描述】:

在回答和评论后编辑:

我如何找到一个网站(例如银行网站)的 IP 地址,该网站通过 post 方法向我的网站(使用 c# 的 asp.net 页面)发送一些特定和需要的数据?

例如:

<form id="form1" method="post" action="my web site url"></form>

假设我有一个用户想从我的网站购买东西!

他/她打开我的网站并选择产品并点击付款。此时我可以通过以下答案获取他们的 IP 地址。

通过点击“支付”,我通过 POST 方法将一些数据(例如 order_id)传输到银行网站。

当用户访问银行网站并转移一些钱时,他们想要取回我的网站!

此时,银行网站通过POST方式将transaction_id等一些数据发送到我的网站以检查付款。

出于某些安全原因并防止模拟此transaction_id 在银行网站和我的网站之间转移,我想在获取他的 POST 数据(第三方 ip 地址)时检查 银行 ip 地址 .

例如,我想在下面的代码中找到 transaction_id Sender 的 ip-address(mean bank):

string transaction_id = Page.Request.Form["transaction_id"];  

但是,如果我检查

string ipaddress = HttpContext.Current.Request.UserHostAddress;  

Request.ServerVariables("REMOTE_ADDR")

这些代码仅返回该用户 IP 地址,而不是 POST 数据的发送者。

【问题讨论】:

  • 你需要多解释一下你在做什么以及你是怎么做的。
  • 我认为您的问题是如何找到通过代理站点向我发送发布请求的最终用户的 IP 地址?我说的对吗?
  • 非常感谢 cmets 和答案/我编辑我的 Q ...
  • 谁是“我”?它是一个 asp.net 页面、一个 WCF web 服务还是其他的东西?通常,获取请求的 IP 应该很容易 - 请参阅 Muhammad 的响应。如果这不能解决你的问题,那么你需要解释一下你的情况是独特的。您在编辑中包含的信息对我们没有帮助。

标签: c# asp.net post action ip-address


【解决方案1】:
 Request.ServerVariables("REMOTE_ADDR")

此链接可能会提供更多详细信息

http://thepcspy.com/read/getting_the_real_ip_of_your_users/

【讨论】:

  • 感谢您的回答/但我认为此代码会返回我的网站访问者 ip(特定会话)/但是发送 ip 地址的发件人数据呢?
  • 我认为在这两种情况下它都会向服务器发送请求。所以这两种情况应该是一样的。
【解决方案2】:

如果你使用的是'Socket',那么你could just do something like the example:

s.Connect (lep);

// Using the RemoteEndPoint property.
Console.WriteLine ("I am connected to " + IPAddress.Parse (((IPEndPoint)s.RemoteEndPoint).Address.ToString ()) + "on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString ());

// Using the LocalEndPoint property.
Console.WriteLine ("My local IpAddress is :" + IPAddress.Parse (((IPEndPoint)s.LocalEndPoint).Address.ToString ()) + "I am connected on port number " + ((IPEndPoint)s.LocalEndPoint).Port.ToString ());

【讨论】:

  • 非常感谢您的 asnwer / 你的代码可以使用套接字 / 但是我的情况呢?
  • @Downvoter:为什么要投反对票?在编辑之前,不清楚 LostLord 是如何进行连接的。我的回答对当时问题中的信息有效。
  • 好的伙计们-感谢上下投票:)我喜欢堆栈/但是我的Q现在清楚了吗?有没有可能找到那个ip?
【解决方案3】:

我们可以使用以下内容吗?还是我错过了什么?

字符串 ipaddress = HttpContext.Current.Request.UserHostAddress;

【讨论】:

  • 一旦用户从你的网络服务器请求一个页面,你可以在服务器端使用“HttpContext.Current.Request.UserHostAddress”获取他的IP地址。
猜你喜欢
  • 2011-10-03
  • 1970-01-01
  • 2016-04-01
  • 2010-10-15
  • 2021-10-25
  • 2011-09-05
  • 1970-01-01
  • 2016-01-10
  • 2015-05-06
相关资源
最近更新 更多