Network IP's
Network IP's
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?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
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
but if u just want to get all of the computers on a windows workgroup/domain, there is a way to do that
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
That's exactly what i want to do... How can i do this?but if u just want to get all of the computers on a windows workgroup/domain, there is a way to do that
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...

Last edited by Inf0Byt3 on Sat Sep 23, 2006 1:06 pm, edited 1 time in total.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
-
- Enthusiast
- Posts: 125
- Joined: Sat Jun 17, 2006 3:15 pm
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
this would be easier to implement by using network broadcasts (udp would be best)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.
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
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
Yes... It seems not to do anything for now... I tried this code too (from the german forums) and still nothing
[Edit]
Ok this works now... Code modified.

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()
Ok this works now... Code modified.
Last edited by Inf0Byt3 on Sat Sep 23, 2006 1:25 pm, edited 1 time in total.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
before the line
add
Code: Select all
DeleteElement(listnetresource())
Code: Select all
Debug "deleted "+listnetresource()\RemoteName
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
-
- Addict
- Posts: 1027
- Joined: Sun May 15, 2005 5:15 am
- Location: Australia
- Contact:
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.Inf0Byt3 wrote:UDP Broadcasts? How is that? I don't really have any experience in networking.
i found some code somewhere on this forum to retreive network adapters and their ips, i'll post it if u need it
Demonio Ardente
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!