Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1118
  • Last Modified:

VBScript: check the computer name

I have a NT4 server (sp3 option pack) with IIS4.
I want to make a .ASP page with a script (VBScript) that can be able to get the computer name of a client (Windows98/95).

I use actually a script that can get the IP address. But i want to use my script with a DHCP server... so the IP is dynamical.
So i want to use now the computer name (to check the properties in a cooky).

Can someone help me ?
(i want to use an API like getcomputername from MS java classes).

Thanx
0
arnaudg
Asked:
arnaudg
1 Solution
 
chabaudCommented:
You cannot call directly API call from VBscript, but you can use automation throught Server.Createobject("theprogid").

So you can get your client computer name from its IP address creating an activex DLL.

Here is an example wrote in VB5:

Option Explicit

Const WSADESCRIPTION_LEN = 256 + 1
Const WSASYS_STATUS_LEN = 128 + 1
Const AF_INET = 2
Const INADDR_NONE = &HFFFFFFFF

Private Type WSADATA
    wHighVersion As Long
    szDescription As String * WSADESCRIPTION_LEN
    szSystemStatus As String * WSASYS_STATUS_LEN
    iMaxSockets As Long
    iMaxUdpDg As Long
    lpVendorInfo As Long
End Type

Private Type HOSTENT
    h_name As Long 'LPSTR
    h_aliases As Long 'LPLPSTR
    h_addrtype As Integer
    h_length As Integer
    h_addr_list As Long 'char FAR * FAR * h_addr_list
End Type
       
Private Type IN_ADDR
    b1 As Byte
    b2 As Byte
    b3 As Byte
    b4 As Byte
End Type
               
Private Declare Function WSAStartup Lib "Wsock32.dll" (ByVal wVersionRequested As Integer, ByRef lpWSAData As WSADATA) As Long
Private Declare Sub WSACleanup Lib "Wsock32.dll" ()
Private Declare Function gethostbyaddr Lib "Wsock32.dll" (addr As Any, ByVal ilen As Long, ByVal itype As Long) As Long
Private Declare Function inet_addr Lib "Wsock32.dll" (ByVal cp As String) As Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, lpString2 As Any) As Long

Public Function GetName(cpAddr As String) As String
   
    Dim Adata As WSADATA
    Dim addr As Long
    Dim ptHost As Long
    Dim host As HOSTENT
    Dim buf As String * 256
   
    GetName = ""
   
    If WSAStartup(&H101, Adata) <> 0 Then Exit Function
   
    addr = inet_addr(cpAddr)
    If addr = INADDR_NONE Then Exit Function
   
    Dim saddr As IN_ADDR
    Dim b As Byte
    CopyMemory ByVal VarPtr(saddr), ByVal VarPtr(addr), 4
    b = saddr.b1
    saddr.b1 = saddr.b4
    saddr.b4 = b
    b = saddr.b2
    saddr.b2 = saddr.b3
    saddr.b3 = b
   
    ptHost = gethostbyaddr(ByVal VarPtr(saddr), 4, AF_INET)
   
    If ptHost <> 0 Then
        CopyMemory ByVal VarPtr(host), ByVal ptHost, 16
        lstrcpy buf, ByVal host.h_name
        GetName = Trim(buf)
    End If
   
    WSACleanup

End Function

INTO your ASP:

dim gcn
Set gcn = Server.Creatobject("GCN.GCN")
alert gcn.GetName("1.2.3.4")
Set gcn = Nothing

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now