locked
HELP : Get Client IP in Vista IIS 7 ? RRS feed

  • Question

  • User-1653607021 posted

    Hi,

    Does anyone know how to get client IP in Vista ?

    I have tried System.Web.HttpContext.Current.Request.UserHostAddress. It works fine if I use File System, 127.0.0.1.

    But after I change to HTTP (using IIS 7) , it returns ::1. Why ?

    Thanks in advance

     

     

    Friday, April 13, 2007 12:14 AM

Answers

  • User1202395857 posted

    Hi,

    in the meantime I have found another way to get the client ip in Vista. There is now an easy .NET way to perform this...

    ServerManager iisManager = new ServerManager();
    foreach(WorkerProcess w3wp in iisManager.WorkerProcesses) {
        Console.WriteLine("W3WP ({0})", w3wp.ProcessId);            
        foreach 
    (Request request in w3wp.GetRequests(0)) {

            Console.WriteLine("{0} - {1},{2},{3}",
                        request.Url,
                        request.ClientIPAddr,
                        request.TimeElapsed,
                        request.TimeInState)
    ;
        
    }
    }

    It is a simple program that uses the new .NET APIs to query IIS7 to get a collection of all active worker processes on the computer, and then print out a list of all current requests being proceeded in each one -- outputting the request's URL, the client-IP address of the remote user, as well as how long it has been executing, and how long it has been in its current state (for example: is it in the authentication module, authorization module, executing within the page, etc).

    HTH,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 16, 2007 10:28 AM

All replies

  • User1202395857 posted

    Hi,

    I think this may be because the LMHOST.SAM file that installs with Vista does not have the last entry "remarked out" and thus it actually loads the 127 address for localhost. In my opinion the ::1 is actually an entry for the IPV6 localhost address...

    Maybe this helps...

    Friday, April 13, 2007 6:27 AM
  • User-1653607021 posted

    Hi,

    Any way to fix this ? Can you show me where is LMHOST.SAM  and what to change in the file ?

    Thanks.

    Monday, April 16, 2007 7:33 AM
  • User1202395857 posted

    Hi,

    in the meantime I have found another way to get the client ip in Vista. There is now an easy .NET way to perform this...

    ServerManager iisManager = new ServerManager();
    foreach(WorkerProcess w3wp in iisManager.WorkerProcesses) {
        Console.WriteLine("W3WP ({0})", w3wp.ProcessId);            
        foreach 
    (Request request in w3wp.GetRequests(0)) {

            Console.WriteLine("{0} - {1},{2},{3}",
                        request.Url,
                        request.ClientIPAddr,
                        request.TimeElapsed,
                        request.TimeInState)
    ;
        
    }
    }

    It is a simple program that uses the new .NET APIs to query IIS7 to get a collection of all active worker processes on the computer, and then print out a list of all current requests being proceeded in each one -- outputting the request's URL, the client-IP address of the remote user, as well as how long it has been executing, and how long it has been in its current state (for example: is it in the authentication module, authorization module, executing within the page, etc).

    HTH,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 16, 2007 10:28 AM