Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program is hosted on a server and i need the ip address of those machine which are trying to log in into my apllication hosted on server.
i have tried many things but i didnt found a single method to find the correct ip.
eg
VB
 strHostName = System.Net.Dns.GetHostName()
        strIPAddress = GetHostByName(strHostName).AddressList(0).ToString()
        Response.Write(Request.Params("REMOTE_ADDR"))
        Response.Write(HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")) 
        Response.Write(HttpContext.Current.Request.UserHostAddress)        Response.Write(Page.Request.ServerVariables("REMOTE_ADDR"))        
Response.Write(Page.Request.ServerVariables("LOCAL_ADDR")) 

please let me know the correct code to get the exact IP.
i have hosted my application on the server
my email id- [removed]@yahoo.com
Posted
Updated 4-Sep-12 0:40am
v3
Comments
PratikShah2366 4-Sep-12 6:40am    
Please let me know i need it in urgent
Richard MacCutchan 4-Sep-12 6:43am    
The urgency of your request is a matter of supreme indifference to the members of CodeProject. If you truly need it urgently then try doing some research for yourself.
Joan M 4-Sep-12 6:53am    
What about sending the IP from the app that is trying to connect as a requirement before establishing the connection?

Try this
C#
public String getIpAddress()
    {
        string strIpAddress;
        strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (strIpAddress == null)
        {
            strIpAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        return Convert.ToString(strIpAddress);
    }


Also have look: Find Computer Name,Operating System name and MAC address of a given IP address using c#[^]
 
Share this answer
 
Comments
Manas Bhardwaj 4-Sep-12 16:16pm    
5+
Prasad_Kulkarni 5-Sep-12 0:00am    
Thank you Manas!
PratikShah2366 5-Sep-12 0:33am    
when i host it through IIS i get it right. but i am hosting it without IIS
 
Share this answer
 
I have used below two in my application. I will recommend you to use 1st one. 2nd one also right.

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.UserHostAddress;
 
Share this answer
 
v2
Comments
PratikShah2366 5-Sep-12 0:33am    
when i host it through IIS i get it right. but i am hosting it without IIS

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900