Results 1 to 3 of 3

Thread: How to get all computers/IP's on a lan automatically?

  1. #1
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    How to get all computers/IP's on a lan automatically?

    Hi folks,

    thanks to the sample Eros posted here long time ago I know now how to send stuff of the LAN. I want to implement multiplayer other the LAN in Airdogs. What is uncomfortable it that you have to enter the IP of your counterpart. In games like Age of Empire, when someone creates a lan game as a server, the others can see it automatically and can log in. I guess for this you need to retrieve the IP's of all connected computers and then send them the info about your game. So my question is, how to retrieve the IP's of all connected computers?

    Cheers
    Michael

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: How to get all computers/IP's on a lan automatically?

    Michael,

    here an example that scan a subnet starting from your local IP.
    Script assumes that your computer have just one IP and one NIC (network interface card)
    It also assumes that your IP config is masked 255.255.255.0
    If all ok, it scan all the 255 possible IP and determine their MAC address.

    In your case, you need a function similar to this script but you need to define your own protocol using your own port (I suggest UDT ports) to comunicate between server and possible clients.
    The first thing to for the server is to open a communication UDT port and remain in listen mode.
    The client when starts, must scan the IP in the subnet and if found a computer send a command (you cna invent whateven here) to the port the server is listening.
    If they exchange the expected data than they can start to exchange other info to agree to some common ports to use during ingame operations.

    ... other stuff will follow but this can give you a go.

    Eros

    [code=thinbasic] '---------
    ' Modules
    '---
    uses "inet"
    uses "console"

    '---------
    ' Constants
    '---
    %MaxIp = 255

    %Pos_IP = 1
    %Pos_Results = 2
    %Pos_Mac = 3

    '---------
    ' Variables
    '---
    dim Counter as long '---Used to count IPs
    dim sIP as string '---Used to form full IP

    dim sResults(3, %MaxIp) as string '---Store results

    '---------
    ' Script
    '---
    '---Determine first IP. ATTENTION, you can have more than one IP configured
    ' both in the same NIC or in different NIC
    dim MyFirstIP as string = INET_GetIp(1)
    console_writeline "My first IP is: " & MyFirstIP

    '---Determine your lan assuming subnet mask is 255.255.255.0
    dim sSubNet as string '---Store initial subnet
    dim lPos as long

    '---Search the position of the 3rd "."
    lPos = instr(MyFirstIP, ".", 3)
    '---If found, extract the subnet part (assuming mask is 255.255.255.0)
    if lPos then
    sSubNet = left$(MyFirstIP, lPos)
    console_writeline "My SubNet is: " & sSubNet
    else
    '---Something wrong
    console_writeline "Something wrong with subnet/ip numbers. Check data."
    console_waitkey
    stop
    end if
    '---

    for Counter = 1 to %MaxIp
    sIP = sSubNet & Counter

    sResults(%Pos_IP , Counter) = sIP
    sResults(%Pos_Results , Counter) = INET_Ping(sIP, 100, "abcdefghijklmnopqrstu")
    sResults(%Pos_Mac , Counter) = INET_GetRemoteMACAddress(sIP)

    Console_writeline _
    format$(Counter, "000") & " " & _
    using$("\ \", sResults(%Pos_IP, Counter)) & _
    using$("\ \", parse$(sResults(%Pos_Results, Counter), $tab, 3)) & _
    sResults(%Pos_Mac, Counter) & _
    ""

    next

    '---Here you can do what you need with IP and mac address pair.

    console_waitkey
    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: How to get all computers/IP's on a lan automatically?

    Thanks Eros, I'll give this a try.

Similar Threads

  1. Who has owned the most computers in his/her life?
    By danbaron in forum Shout Box Area
    Replies: 2
    Last Post: 15-11-2010, 02:24
  2. Realtime visuals on computers
    By ErosOlmi in forum Technology
    Replies: 6
    Last Post: 23-05-2007, 22:31

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •