Using Client IP address in HttpWebRequest

2019-07-31 08:16发布

问题:

What I need is quite the same asked here, I don't understand the answer too well, because of my knowledge, so maybe someone could help me.

What I'd like to do is using the connected user's IP address (Client IP) to make the server-side HttpWebRequest, so I would grab the user's IP and make the call with it.

What I'd like to obtain is that every connected user makes HttpWebRequests with their IP.

Is it possible?

If it is, how should I edit that code to do this?

Thanks.

回答1:

This is impossible. My answer to the other question was about selecting which IP Address (read: network adapter) to use for a request. However, you cannot invent IP Addresses out of thin air, nor use IP Addresses that are not yours (in a physical, attached-to-this-computer sense).

Now, technically, using Raw Sockets, you can spoof another IP Address in your packets. However, the problem with that is that the return traffic will go to the IP Address you specify, not the one you actually have!

So, my advice is to not pursue this line of thought any further, and find another way to do whatever it is that you are trying to do.



回答2:

You may only make outbound connections from your server using an IP that is assigned to the server. If you tried to use a client's IP, it would fail.

Even if it did not fail, it would be a form of spoofing and would fail pretty qucikly anyway- the handshake that occurs using tcpip would case the remote connection to send an acknowledge packet back to the source ip (in your case, the client ip) which would result in an error.

If you are using UDP, it actually is possible to do this, but that is a different subject.