Click here to Skip to main content
16,015,755 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi How to get server ip raddress,i.e website publish and paste in iis in one system,from that client can assess website using server ip address,some time server ip address can change ,so when client use the site can get where the publish copy is paste.
For why i am ask this question,i need to check with client machine,i.e server ip and client ip from client machine,if both are not same i need to hide something ,otherwise no need to hide , so only i ask here,

so how to get server ip and current system ip address.

VB
Dim IP As String
    Dim IPAdd As String = String.Empty
    IPAdd = Request.ServerVariables("SERVER_NAME")

    Dim ipEntry As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
    Dim IpAddr As IPAddress() = ipEntry.AddressList


if i run this code i get both IP and IpAddr are same in client machine,but website deploy in another machine

Regards
Aravind
Posted
Updated 20-Aug-13 21:41pm
v2

Hi i solved this question by myslef

VB
Dim SERVERIP As String
      Dim CLIENTIP As String = String.Empty


      Dim ipEntry As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
      Dim IpAddr As IPAddress() = ipEntry.AddressList
      Dim cur As String = Request.UserHostAddress()
      SERVERIP = IpAddr(0).ToString()

      CLIENTIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
      If CLIENTIP = "" Then
          CLIENTIP = Request.ServerVariables("REMOTE_ADDR")
      End If



     If (CLIENTIP = "::1") Then
         'If here code executes  ---means server
      Else
          'If here code executes  ---means not server
      End If
 
Share this answer
 
Since you say: "some time server ip address can change" that means you are using a Dynamic IP address, which means it is a very poor idea to have your clients access your site via the IP address directly at all. Dynamic IPs mean that it isn't fixed: it will be allocated as needed, and your IP today could be my IP tomorrow. This means your client software might work, but not as you intended...

Either pay the extra for a Static IP, or access your site via the Domain name instead and let the DNS sort out the current IP address.
 
Share this answer
 
Comments
Aravindba 21-Aug-13 3:08am    
Thank u for ur reply and idea,but for testing people can test in 2 or 5 system make it as sever and they can test,so i need to change the server ip address inside the coding for whether client or server,so only i ask

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