1

EDIT after Answers AND Comments :

How can i find the IP address of a web site (for example bank web site) that is sending to my web site (asp.net page with c#) some specific and needed data by post method?

For example :

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

Imagine that I have a user that wants to buy something from my web site!

He/She opens my web site and choose a product and click pay. At this time I can get their ip address by the below answers.

By clicking "pay" I transfer some data such as order_id to a bank web site by a POST method.

When the user goes to the bank website and transfers some money, they then want to get back my web site!

At this time,the bank site sends some data such as transaction_id by a POST method to my web site for checking payment.

For some security reasons and to prevent simulation this transaction_id transfers between the bank site and my web site, I want to check bank ip address when getting his POST data (third party ip address).

For example I want to find the ip-address(mean bank) of transaction_id Sender at below code :

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

However, if I check

string ipaddress = HttpContext.Current.Request.UserHostAddress;  

or

Request.ServerVariables("REMOTE_ADDR")

these codes return only that user IP address, not sender of POST data.

Peter K.
  • 8,028
  • 4
  • 48
  • 73
SilverLight
  • 19,668
  • 65
  • 192
  • 300
  • You need to explain a little more about what you're doing and how you're doing it. – Peter K. Jul 22 '11 at 17:27
  • Please have a look at this thread and get code http://stackoverflow.com/questions/1907195/how-to-get-ip-address/1907204#1907204 – Muhammad Akhtar Jul 22 '11 at 17:27
  • I think your question is **how to find the IP address of the end user who has sent me a post request via a proxy site**? Am I right? – Saeed Neamati Jul 22 '11 at 17:32
  • really thanks for comments and answers / i edit my Q ... – SilverLight Jul 22 '11 at 17:34
  • Who is "me"? Is it a an asp.net page, a WCF webservice, or something different? Generally, getting the IP of a request should be easy - see Muhammad's response. If this does not solve your problem, then you need to explain what about your situation is unique. The information you included in your edit isn't helping us. – Jason Jul 22 '11 at 19:19
  • dear jason - i edit my Q again with full explanation about my situation ... – SilverLight Jul 22 '11 at 23:45
  • Are you sure the bank is posting directly to you? It sounds like they are just causing the user's browser to post back to you after the transaction completes. – Jason Jul 25 '11 at 16:32
  • You should consider marking it as an answer. – Pit Digger Sep 08 '11 at 18:50

3 Answers3

2
 Request.ServerVariables("REMOTE_ADDR")

This link might give more details

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

Pit Digger
  • 9,618
  • 23
  • 78
  • 122
  • thanks for answer / but i think this code returns my website visitors ip (specific session) / but what about sender data by post ip address ? – SilverLight Jul 22 '11 at 17:29
  • I think in both cases its going to send a request to the server . So this should be the same in both cases. – Pit Digger Jul 22 '11 at 17:33
1

If you are using 'Socket', then you 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 ());
Peter K.
  • 8,028
  • 4
  • 48
  • 73
  • really thanks for your asnwer / ur codes are ok for working with sockets / but what about my situation ? – SilverLight Jul 22 '11 at 17:39
  • @Downvoter: Why the downvote? Before the edit, it wasn't clear how LostLord was doing the connection. My answer was valid for the information in the question at the time. – Peter K. Jul 22 '11 at 18:12
  • ok guys - thanks for down and up voting :) i love stack / but is my Q clear now ? is it possible to find that ip ? – SilverLight Jul 22 '11 at 18:45
1

Can we use the following? Or am I missing something?

string ipaddress = HttpContext.Current.Request.UserHostAddress;

Win
  • 61,100
  • 13
  • 102
  • 181
  • As soon as user requests a page from your web server, you can get his IP address by using "HttpContext.Current.Request.UserHostAddress" at server side. – Win Jul 22 '11 at 21:21