Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Look for hosts in LAN network

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Look for hosts in LAN network

    Hi.
    I am currently working on an application which has some networking going on.
    A user can start a local server and others can connect to it if they know the IP-adress of the host.
    I would like to make this a little bit simpler. Ideally the clients could scan for any hosts which are available in the local area network. The user could then select the host from a list and connect to it automatically without having to know the IP-adress at all.

    So my question is: How do I implement this "scanning" for local hosts? I would rather not try to open a Connection to every possible LAN-Adress and see which one gets accepted and which one wont be.
    Some kind of LAN broadcasting (from the server to all possible clients) could also be possible I guess;

    (I am using standard Java sockets / serverSockets by the way)

    Thank you in advance.


  2. #2
    Member
    Join Date
    Feb 2014
    Posts
    180
    Thanks
    0
    Thanked 48 Times in 45 Posts

    Default Re: Look for hosts in LAN network

    I'm not very familiar with this topic, but it seems that a MulticastSocket might help. See Broadcasting to Multiple Recipients (The Java™ Tutorials > Custom Networking > All About Datagrams).

  3. The Following User Says Thank You to jashburn For This Useful Post:

    Wizand (June 8th, 2014)

  4. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Look for hosts in LAN network

    Thanks for the response, I will take a look at it.
    At the moment I was working with DatagramSockets sending a small package every X seconds to every adress in the LAN.

    By the way, I noticed how stupid the title is: "LAN network"; what was I thinking...

  5. #4
    Junior Member
    Join Date
    Dec 2017
    Location
    United States
    Posts
    5
    Thanks
    0
    Thanked 6 Times in 1 Post

    Default Re: Look for hosts in LAN network

    I'm not an expert in LAN network, but I read a blog on the same. Please check this & see if this can help you - https://www.fieldengineer.com/blogs/...-wireless-lan/
    A B.Tech IT Graduate, an avid reader who loves to travel to beautiful places, and cooks in free time.
    Read my Blog - What is Wireless LAN

  6. #5

    Default Re: Look for hosts in LAN network

    I always use nmap. To scan for all devices in your network, use:

    nmap -sP 192.168.0.1/24

    It is a great tool to have in the know. You may want to install nmap using:

    sudo apt-get install nmap if you are using Debian or

    sudo yaourt -S nmap if you are using Arch.

Similar Threads

  1. Lan chat applet
    By adnan88 in forum The Cafe
    Replies: 3
    Last Post: January 21st, 2013, 07:16 AM
  2. how to get the available server in the lan
    By sxlend in forum Java Networking
    Replies: 2
    Last Post: July 26th, 2012, 02:55 AM
  3. a Lan hosts representation with a j Tree
    By ola50 in forum Java Networking
    Replies: 0
    Last Post: May 15th, 2012, 10:18 PM
  4. how to edit hosts file in windows7 using java program ?
    By vijay_p in forum Java Theory & Questions
    Replies: 3
    Last Post: December 2nd, 2011, 07:14 AM