Network IP's

Just starting out? Need help? Post your questions and find answers here.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Network IP's

Post 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?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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... :)
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)
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post by ..::Origin::.. »

Why not (on the client side) use a script to determine it there then send it to the server?
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thanks! When i try to run it, it doesn't do anything... Shouldn't it debug stuff??
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

are there any other windows computer running?
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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.
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)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

before the line

Code: Select all

DeleteElement(listnetresource())
add

Code: Select all

Debug "deleted "+listnetresource()\RemoteName
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

if u want help with udp broadcasts, i would be glad to help
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

UDP Broadcasts? How is that? I don't really have any experience in networking :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post 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
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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!
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply