Tuesday, September 2, 2008

Get the machine name of the remote PC - asp.net

Dim IPaddress As String
IPaddress = Request.ServerVariables("REMOTE_ADDR")

'This is one of many server variables available in
'asp.net. You can view the other variables, but adding
'trace="true" to the page directive....
'@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 'Inherits="_Default" Trace="true"


Response.Write("The IP address is: " + IPaddress)

Dim ComputerName As String
ComputerName = System.Net.Dns.GetHostEntry(IPaddress).HostName()

'System.Net
'The System.Net namespaces provides a simple programming interface
'for many of the protocols used in networks.


'Dns
'The Dns class provides simple domain name resolution functionality

'GetHostEntry - function
'Resolves a host name or IP address to a System.Net.IpHostEntry instance
'It can take as a parameter a
'1-Host name or IP address as the string
'or
'2-System.Net.IpAddress

'HostName is a get or set public property

Response.Write("The computer name is: " + ComputerName)

No comments: