如何在asp.net中获取服务器IP地址? [英] How to get server ip address in asp.net ?

查看:297
本文介绍了如何在asp.net中获取服务器IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
如何获取服务器ip raddress,即网站发布并在一个系统中粘贴iis,从该客户端可以使用服务器ip地址评估网站,一些时间服务器的ip地址可以改变,所以当客户端使用网站可以获得发布副本粘贴的位置。

为什么我问这个问题,我需要检查客户端机器,即客户端机器上的服务器IP和客户端IP,如果两者不相同我需要隐藏一些东西,否则不需要隐藏,所以只有我问这里,



所以如何获取服务器IP和当前系统IP地址。



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.

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





如果我运行此代码我得到IP和IpAddr在客户端机器中是相同的,但网站部署在另一个机器



问候

Aravind



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

Regards
Aravind

推荐答案

既然你说:一些时间服务器IP地址可以更改这意味着您正在使用动态IP地址,这意味着让您的客户端直接通过IP地址访问您的站点是一个非常糟糕的主意。动态IP意味着它没有修复:它将根据需要进行分配,今天你的IP可能是我明天的IP。这意味着您的客户端软件可能有效,但不是您想要的...



要么为静态IP支付额外费用,要么通过域名访问您的网站并让DNS整理当前的IP地址。
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.


Hi
i解决了这个问题由myslef



Hi i solved this question by myslef

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


这篇关于如何在asp.net中获取服务器IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆