I'm working with HTTP requests using an HttpListener and I need to log the IP address of the sender. I've tried searching online, but I'm getting a mix of methods that don't seem to fit my situation. Any advice would be much appreciated!
3 Answers
In your case, the sender's IP might be part of the server variables. You can refer to the documentation for the HttpRequest class in .NET to find relevant properties that could include the IP address you're looking for.
One straightforward way to get the sender's IP address is to check the RemoteAddr header. I'm not sure how it's done specifically in PowerShell, but if you're using a reverse proxy like Cloudflare, they have detailed instructions on how to access it as well. If you're running an nginx server, there's a way to configure that too.
It sounds like you're using the Http Listener, but that's pretty broad. Can you clarify what exact version or commands you are employing? There are a few different implementations, and that could change how you access the IP address.

Thanks for your reply! I'm using a more recent version of PowerShell, but I don't have a specific command at hand. Any suggestions?