If you know the IP addresses of the computers on your network there is a way to ping addresses using VB and a way to return the computer name using the ip address. I have an excel spreadsheet of all the computer IP addresses on my network. There is a button on the form that will ping all the IP addresses in column A and return the status of the address (online or timeout) and return the computer name for that IP address (even if the user has changed the computer name). But once again, you must know the IP addresses first. I can send you the spreadsheet if you want or just post the code if you wish. Its a very handy application since I always need to know the status of my wireless hubs in production areas.
Here you go. Just copy this into a module and use the function:
GetHostNameFromIP([your ip address STRING])
'---START CODE ---
Option Explicit
Private Const WSADescription_Len As Long = 256
Private Const WSASYS_Status_Len As Long = 128
Private Const WS_VERSION_REQD As Long = &H101
Private Const IP_SUCCESS As Long = 0
Private Const SOCKET_ERROR As Long = -1
Private Const AF_INET As Long = 2
Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
imaxsockets As Integer
imaxudp As Integer
lpszvenderinfo As Long
End Type
Private Declare Function WSAStartup Lib "wsock32" _
(ByVal VersionReq As Long, _
WSADataReturn As WSADATA) As Long
Private Declare Function WSACleanup Lib "wsock32" () As Long
Private Declare Function inet_addr Lib "wsock32" _
(ByVal s As String) As Long
Private Declare Function gethostbyaddr Lib "wsock32" _
(haddr As Long, _
ByVal hnlen As Long, _
ByVal addrtype As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(xDest As Any, _
xSource As Any, _
ByVal nbytes As Long)
Private Declare Function lstrlen Lib "kernel32" _
Alias "lstrlenA" _
(lpString As Any) As Long
If WSACleanup() <> 0 Then
MsgBox "Windows Sockets error occurred in Cleanup.", vbExclamation
End If
End Sub
Public Function GetHostNameFromIP(ByVal sAddress As String) As String
Dim ptrHosent As Long
Dim hAddress As Long
Dim nbytes As Long
If SocketsInitialize() Then
'convert string address to long
hAddress = inet_addr(sAddress)
If hAddress <> SOCKET_ERROR Then
'obtain a pointer to the HOSTENT structure
'that contains the name and address
'corresponding to the given network address.
ptrHosent = gethostbyaddr(hAddress, 4, AF_INET)
I did not create that code, I take no credit for it. I take no responsibility for any adverse results from using that code. (although, there shouldn't be any) It was tested on a Windows2000 PC. Remember, use code from this forum at your own risk!
Sorry, im a newbie with modules (i haven't used them before) im a bit confused, I ve copyed the code into a module but what do i put in the form's code?
Oh, i understand now...yes that code you gave me works but it isn't quite what i was looking for. Sorry its my fault for asking the wrong qusetion...What i ment was the i have a list box and i want it to show the computers which come up in Network Neighborhood.
It will list all shares and servers on the network by name
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
That tells me every thing about the computer im using, not the names of all the computers in Network Neighborhood. im using a home network which makes the computers path "\\" & 'the computer's name' & "\" like if they are a directory.
If im talking nonsence, im confused.
I've just run it on my home network and it gives this:
Domain... WORKGROUP
Server... \\EILEEN
Server... \\LAPTOP
Server... \\CHRIS
Server... \\JOHN1 John1
Share... \\EILEEN\eileens C
Share... \\EILEEN\D
Share... \\EILEEN\Eileens LJ4 HP LaserJet 4Si
Share... \\JOHN1\SharedDocs
Share... \\JOHN1\Johns Pictures
Share... \\JOHN1\Audio CD (D)
Share... \\JOHN1\Audio CD (E)
Share... \\JOHN1\Printer Epson Stylus COLOR 740 ESC/P 2
Just taking the Server entries appears to give just what you asked.
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'People who live in windowed environments shouldn't cast pointers.'
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.