Page 1 of 1
Network IP's
Posted: Sat Sep 23, 2006 11:20 am
by Inf0Byt3
Is there any way of ennumerating all the IP's of the computers on a LAN Network? I've seen that it is possible of getting even the computer's name, the logged user name, etc... But how to achieve this?
Posted: Sat Sep 23, 2006 12:36 pm
by lexvictory
im not sure if theres a way to get all the ips unless u have a program that u've made running on them;
but if u just want to get all of the computers on a windows workgroup/domain, there is a way to do that
Posted: Sat Sep 23, 2006 12:49 pm
by Inf0Byt3
but if u just want to get all of the computers on a windows workgroup/domain, there is a way to do that
That's exactly what i want to do... How can i do this?
I am trying to make a LAN chat software and i need this in order to find the workgroup computers automatically, instead of letting the user add the ip's manually.
[Edit]
Like BorgChat does...

Posted: Sat Sep 23, 2006 1:00 pm
by ..::Origin::..
Why not (on the client side) use a script to determine it there then send it to the server?
Posted: Sat Sep 23, 2006 1:08 pm
by lexvictory
Inf0Byt3 wrote:I am trying to make a LAN chat software and i need this in order to find the workgroup computers automatically, instead of letting the user add the ip's automatically.
this would be easier to implement by using network broadcasts (udp would be best)
but here is the (modified) code to enumerate netbios names - it wasnt my code originaly, found it somewhere on this forum
Code: Select all
; '==============================================================================
; ' Network Resource List.
; ' Enumerate all of the networks and network resources available to the
; ' current machine.
; ' converted using http://www.powerbasic.com/support/forums/Forum6/HTML/001494.html
; '==============================================================================
#Window_Main = 0
#Gadget_ListIcon = 0
Structure NEWNETRESOURCE
Scope.l
Type.l
DisplayType.l
Usage.l
LocalName.s
RemoteName.s
Comment.s
Provider.s
EndStructure
NewList ListNETRESOURCE.NEWNETRESOURCE()
Procedure EnumAll(*nr.NETRESOURCE)
tempnr.NETRESOURCE
j.l
x.l
Entries = -1
nSize = 16384
*Buffer=AllocateMemory(nSize)
ec = WNetOpenEnum_(#RESOURCE_GLOBALNET, #RESOURCETYPE_ANY, #RESOURCEUSAGE_CONTAINER, *nr, @hEnum)
If hEnum
ec = WNetEnumResource_(hEnum, @Entries, *Buffer, @nSize)
For x = 1 To Entries
j = (x-1) * SizeOf(NETRESOURCE)
tempnr\dwScope = PeekL(*Buffer+j+0)
tempnr\dwType = PeekL(*Buffer+j+4)
tempnr\dwDisplayType = PeekL(*Buffer+j+8)
tempnr\dwUsage = PeekL(*Buffer+j+12)
tempnr\lpLocalName = PeekL(*Buffer+j+16)
tempnr\lpRemoteName = PeekL(*Buffer+j+20)
tempnr\lpComment = PeekL(*Buffer+j+24)
tempnr\lpProvider = PeekL(*Buffer+j+28)
AddElement(ListNETRESOURCE())
Select tempnr\dwScope
Case #RESOURCE_CONNECTED
ListNETRESOURCE()\Scope = #RESOURCE_CONNECTED
Case #RESOURCE_GLOBALNET
ListNETRESOURCE()\Scope = #RESOURCE_GLOBALNET
Case #RESOURCE_REMEMBERED
ListNETRESOURCE()\Scope = #RESOURCE_REMEMBERED
Default
ListNETRESOURCE()\Scope = -100
EndSelect
Select tempnr\dwType
Case #RESOURCETYPE_ANY
ListNETRESOURCE()\Type = #RESOURCETYPE_ANY
Case #RESOURCETYPE_DISK
ListNETRESOURCE()\Type = #RESOURCETYPE_DISK
Case #RESOURCETYPE_PRINT
ListNETRESOURCE()\Type = #RESOURCETYPE_PRINT
Default
ListNETRESOURCE()\Type = -100
EndSelect
Select tempnr\dwDisplayType
Case #RESOURCEDISPLAYTYPE_DOMAIN
ListNETRESOURCE()\DisplayType = #RESOURCEDISPLAYTYPE_DOMAIN
Case #RESOURCEDISPLAYTYPE_GENERIC
ListNETRESOURCE()\DisplayType = #RESOURCEDISPLAYTYPE_GENERIC
Case #RESOURCEDISPLAYTYPE_SERVER
ListNETRESOURCE()\DisplayType = #RESOURCEDISPLAYTYPE_SERVER
Case #RESOURCEDISPLAYTYPE_SHARE
ListNETRESOURCE()\DisplayType = #RESOURCEDISPLAYTYPE_SHARE
Default
ListNETRESOURCE()\DisplayType = -100
EndSelect
Select tempnr\dwUsage
Case #RESOURCEUSAGE_CONNECTABLE
ListNETRESOURCE()\Usage = #RESOURCEUSAGE_CONNECTABLE
Case #RESOURCEUSAGE_CONTAINER
ListNETRESOURCE()\Usage = #RESOURCEUSAGE_CONTAINER
Default
ListNETRESOURCE()\Usage = -100
EndSelect
If tempnr\lpLocalName
ListNETRESOURCE()\LocalName = PeekS(tempnr\lpLocalName)
Else
ListNETRESOURCE()\LocalName = ""
EndIf
If tempnr\lpRemoteName
ListNETRESOURCE()\RemoteName = PeekS(tempnr\lpRemoteName)
Else
ListNETRESOURCE()\RemoteName = ""
EndIf
If tempnr\lpComment
ListNETRESOURCE()\Comment = PeekS(tempnr\lpComment)
Else
ListNETRESOURCE()\Comment = ""
EndIf
If tempnr\lpProvider
ListNETRESOURCE()\Provider = PeekS(tempnr\lpProvider)
Else
ListNETRESOURCE()\Provider = ""
EndIf
If (tempnr\dwUsage And #RESOURCEUSAGE_CONTAINER)
If tempnr\dwDisplayType = #RESOURCEDISPLAYTYPE_SERVER
Else
EnumAll(tempnr)
EndIf
EndIf
Next
WNetCloseEnum_(hEnum)
FreeMemory(*Buffer)
EndIf
EndProcedure
;
; Main starts here
;
EnumAll(#Null)
ForEach listnetresource()
If listnetresource()\DisplayType = #RESOURCEDISPLAYTYPE_SERVER
Else
DeleteElement(listnetresource())
EndIf
Next
ForEach listnetresource()
Debug listnetresource()\RemoteName
Next
if the code is stuffed up by the forum, i will send it via email if ure still interested
Posted: Sat Sep 23, 2006 1:16 pm
by Inf0Byt3
Thanks! When i try to run it, it doesn't do anything... Shouldn't it debug stuff??
Posted: Sat Sep 23, 2006 1:20 pm
by lexvictory
are there any other windows computer running?
Posted: Sat Sep 23, 2006 1:23 pm
by Inf0Byt3
Yes... It seems not to do anything for now... I tried this code too (from the german forums) and still nothing
Code: Select all
#MAX_PREFERRED_LENGTH = -1
#SV_TYPE_ALL = $FFFFFFFF
#NERR_SUCCESS = 0
#ERROR_MORE_DATA = 234
#MainWindow = 100
#MMTB = 200
Structure SERVER_INFO_101
dwPlatformId.l
lpszServerName.l
dwVersionMajor.l
dwVersionMinor.l
dwType.l
lpszComment.l
EndStructure
Structure LAN_RESULT
Name.s
IP_Name.s
Aktiv_Server.l ; 1, wenn dort ein aktiver Server gefunden werden konnte, dann sind auch die weiteren Daten belegt
Spiel_Name.s
Spieler_bisher.l
EndStructure
Global NewList LAN_Client.LAN_RESULT()
Procedure.s GetIPbyName (NameIP.s)
TheIPAdress.s
pHostinfo = gethostbyname_(NameIP)
If pHostinfo = 0
TheIPAdress = "Unable to resolve domain name"
Else
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype <> #AF_INET
MessageRequester("Info","A non-IP address was returned",0)
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
TheIPAdress = StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0)
AdressNumber+1
Wend
EndIf
EndIf
ProcedureReturn TheIPAdress
EndProcedure
Procedure GetLANList()
IPResult.s
se101.SERVER_INFO_101
nStructSize = SizeOf(SERVER_INFO_101)
RetCode = NetServerEnum_(0, 101, @bufptr, #MAX_PREFERRED_LENGTH, @dwEntriesread, @dwTotalentries, #SV_TYPE_ALL, 0, @dwResumehandle)
If RetCode = #NERR_SUCCESS And RetCode <> #ERROR_MORE_DATA
For i = 0 To dwEntriesread - 1
CopyMemory( bufptr + (nStructSize * i),@se101, nStructSize)
Buffer.s=Space(512)
result=WideCharToMultiByte_(#CP_ACP, 0, se101\lpszServerName, 255, @Buffer.s, 512, 0, 0)
IPResult = GetIPbyName (Buffer)
AddElement(LAN_Client())
Debug Buffer
LAN_Client()\Name = Buffer
LAN_Client()\IP_Name = IPResult
Next
Else
MessageRequester("Info","Failed",0)
EndIf
NetApiBufferFree_(bufptr)
EndProcedure
GetLANList()
[Edit]
Ok this works now... Code modified.
Posted: Sat Sep 23, 2006 1:24 pm
by lexvictory
before the line
add
Code: Select all
Debug "deleted "+listnetresource()\RemoteName
Posted: Sat Sep 23, 2006 1:26 pm
by lexvictory
if u want help with udp broadcasts, i would be glad to help
Posted: Sat Sep 23, 2006 1:28 pm
by Inf0Byt3
UDP Broadcasts? How is that? I don't really have any experience in networking

.
Posted: Sat Sep 23, 2006 1:34 pm
by lexvictory
Inf0Byt3 wrote:UDP Broadcasts? How is that? I don't really have any experience in networking

.
with udp broadcasts, it is sent to an ip ending in 255, eg 192.168.0.255; and all computers with with an ip in the 192.168.0.x range will receive/see the packet.
i found some code somewhere on this forum to retreive network adapters and their ips, i'll post it if u need it
Posted: Sat Sep 23, 2006 2:20 pm
by Inf0Byt3
Wow, that's great! Thank you for all the help!
[Edit]
I'll try the code i have around and if it fails, i'll PM you. Thanks!