close

上網找了好久...終於找到了!!

'取得IP
Function GetClientIP(ByVal HostName As String) As String
      Dim entry As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(HostName)
      Dim sIP As String = ""

      For Each IPAddress As System.Net.IPAddress In entry.AddressList
            sIP = IPAddress.ToString
      Next
      Return sIP

End Function

用法:

Dim getIP As String = GetClientIP(System.Net.Dns.GetHostName)

 

 

另外記錄一下在WEB的環境取IP

Public Function GetClientIP() As String
      Dim result As String = HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")
      If result Is Nothing OrElse result = [String].Empty Then
            result = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
      End If
      If result Is Nothing OrElse result = [String].Empty Then
            result = HttpContext.Current.Request.UserHostAddress
      End If
      If result = "" Then
            '
取Server Web IP
            result = System.Web.HttpContext.Current.Request.ServerVariables("Local_Addr")
      End If
      Return result
End Function

arrow
arrow
    文章標籤
    .NET
    全站熱搜

    雅雅 發表在 痞客邦 留言(0) 人氣()