Broadcasting but not getting all the machine in the network

Discussion in 'Java' started by BigZero, Apr 15, 2008.

  1. BigZero

    BigZero Guest

    Hello,

    here is the code that broadcast the message in Lan, we have around 50
    to 60 machines in Lan,
    all i m looking for the ip address of up machine in lan
    the problem with following code that it not getting all machine ip
    address


    import java.io.* ;
    import java.net.* ;

    public class JavaPing {
    public static String[] upmachine = new String[100];
    public static int i;


    public static void main ( String args[ ] ) {

    String host = "192.168.1.150" ; // default host put what you
    want here
    if ( args.length != 0 ) host = args[0] ;

    int port = 7 ; // echo service port

    String msg = "Test Message" ; // some text
    byte[] outbuff = msg.getBytes() ;
    int len = outbuff.length ;

    long tret ;

    DatagramPacket packout , packin ;

    try {

    System.out.println("\n==> Resolving: " + host + " ..." ) ;
    InetAddress iaddr = InetAddress.getByName( host ) ;

    packout = new DatagramPacket( outbuff , len , iaddr , port ) ;
    // packin = new DatagramPacket( new byte[100] , 100 ) ;
    packin = new DatagramPacket( new byte[1024] , 100 ) ;

    DatagramSocket sock = new DatagramSocket() ;

    // System.out.println("\nLocal Port #:" + sock.getLocalPort() ) ;

    sock.send( packout ) ; // send packet

    tret = System.currentTimeMillis() ; // get time

    System.out.println("\n==> Packet sent to: " + iaddr.toString()+
    " Port: " + port ) ;

    sock.setSoTimeout(10000) ; // rcv timeout = 10 secs.


    while (sock != null)
    {
    sock.receive( packin ) ; // wait for packet...

    tret = System.currentTimeMillis() - tret ; // calc elapsed
    time

    System.out.println("\ntime elapsed: " + tret + " [ms]" ) ;

    //sock.close() ;

    System.out.println("\n==> Packet Rcvd from: " +
    packin.getAddress()+" Data: " + packin.getLength() + " bytes\n" ) ;

    upmachine = (packin.getAddress().toString()).substring(1);
    i++;
    System.out.println( new String(packin.getData() ).trim() ) ;
    }

    }

    catch ( Exception e ) {

    System.out.println( "\n" + e ) ;
    // i--;
    // upmachine = "\0";
    }
    System.out.println("The Up Machine in Lan");
    for( int j = 0;j < i; j++ )
    System.out.println("ip = "+upmachine[j]);

    } // end main

    } // end Class

    this is the code that works fine but getting only few machine
    address,plz direct me to do the work


    Thanks
    VM
     
    BigZero, Apr 15, 2008
    #1
    1. Advertising

  2. BigZero

    Mark Space Guest

    BigZero wrote:

    > here is the code that broadcast the message in Lan, we have around 50
    > to 60 machines in Lan,
    > all i m looking for the ip address of up machine in lan
    > the problem with following code that it not getting all machine ip
    > address


    I'm sorry but I don't see where you put the broadcast address in the
    outbound packet. Could you point it out to me?

    Do you perhaps mean ping or echo request instead of broadcast?

    Can you use your OS "ping" from the command line to verify that the
    machines that don't respond are in fact capable of responding? Some
    machines firewall off port 7 and won't respond. Some firewall off a lot
    more than that, so even the OS "ping" command might not work.

    Can you use a different port for testing? Say one above 1024?
     
    Mark Space, Apr 15, 2008
    #2
    1. Advertising

  3. BigZero

    BigZero Guest

    i m sorry i just missed the broadcast address,
    here the address String host = "192.168.1.150" ; can be set to
    192.168.1.255/255.255.255.255 both r working fine,but reply from only
    6 machine,
    we come to known that these r Linux/Unix machines,so is there any way
    i can do it for windows boxes.
    we have around 50 to 60 machine including servers






    Thanks
    Vijay
     
    BigZero, Apr 16, 2008
    #3
  4. BigZero

    Mark Space Guest

    BigZero wrote:
    > i m sorry i just missed the broadcast address,
    > here the address String host = "192.168.1.150" ; can be set to
    > 192.168.1.255/255.255.255.255 both r working fine,but reply from only
    > 6 machine,


    How are both working fine if only 6 machines reply?

    Please use correct English. Spelling "are" as "r" doesn't help your
    posts get answers.

    Did you try ping?
     
    Mark Space, Apr 16, 2008
    #4
  5. BigZero

    Nigel Wade Guest

    BigZero wrote:

    > i m sorry i just missed the broadcast address,
    > here the address String host = "192.168.1.150" ; can be set to
    > 192.168.1.255/255.255.255.255 both r working fine,but reply from only
    > 6 machine,
    > we come to known that these r Linux/Unix machines,so is there any way
    > i can do it for windows boxes.
    > we have around 50 to 60 machine including servers
    >


    To get a response to the "echo" service that service must be running and
    listening [by default] on port 7. It must also not be blocked by a firewall.

    If you want all your machines to respond you need to ensure that the above two
    criteria are met on every machine. It is a matter of finding out how the OS on
    each system provides an "echo" service (if it does so at all) and enabling it,
    then allowing it through any firewalls. This is not a Java problem so you
    should ask on support groups for the OS/firewalls in question.

    You could make it into a Java problem by writing your own echo service in Java.

    --
    Nigel Wade
     
    Nigel Wade, Apr 17, 2008
    #5
  6. BigZero

    BigZero Guest

    ok both means any one can works ,both results the same output ,
    that is only 6 machine reply and all 6 machines r Unix/Linux box









    Thanks
    Vijay
     
    BigZero, Apr 17, 2008
    #6
  7. BigZero

    BigZero Guest

    You could make it into a Java problem by writing your own echo service
    in Java

    what is this ?








    Thanks
    Vijay
     
    BigZero, Apr 17, 2008
    #7
  8. BigZero

    Nigel Wade Guest

    BigZero wrote:

    > You could make it into a Java problem by writing your own echo service
    > in Java


    You need to learn how to quote and get attributions correct.

    >
    > what is this ?
    >


    What is what, the echo service? The echo service is what you are trying to use
    and, given that you mention it in the comments in your code (it is your code
    isn't it?) I presumed you knew that.

    --
    Nigel Wade
     
    Nigel Wade, Apr 17, 2008
    #8
  9. BigZero wrote:
    > You could make it into a Java problem by writing your own echo service
    > in Java
    >
    > what is this ?
    >


    It is a service, that you would write, using Java, that listens for
    packets arriving at the UDP ECHO port.

    Unless you are exactly implementing the UDP echo service according to
    the RFCs, it would be better to use a port number that is not
    registered. That means one in the range 49151-65535.
    http://www.iana.org/assignments/port-numbers

    Having written this service you would deploy it on every computer that
    you want to be able to monitor.

    A service is a program that runs in the background - called a daemon on
    Unix, a service on Windows. Usually started automatically.

    IIRC you've been given examples, references, APIs and tutorials for this
    before.
    http://java.sun.com/docs/books/tutorial/networking/datagrams/clientServer.html

    --
    RGB
     
    RedGrittyBrick, Apr 17, 2008
    #9
  10. BigZero

    BigZero Guest

    Ok,Thanks man,







    Regards
    Vijay
     
    BigZero, Apr 17, 2008
    #10
  11. BigZero

    BigZero Guest

    Well this service runs only in Server machine,
    gets the up machine in Lan and by using these ip ill call back again
    to those ip for snmp service









    Regards
    Vijay
     
    BigZero, Apr 17, 2008
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    broadcasting a signal

    valentin tihomirov, Sep 22, 2004, in forum: VHDL
    Replies:
    11
    Views:
    770
    Jim Lewis
    Sep 23, 2004
  2. Fax Broadcasting

    , Sep 25, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    483
    Lucas Tam
    Sep 25, 2005
  3. =?Utf-8?B?S2VubnkgTS4=?=

    broadcasting a live conference

    =?Utf-8?B?S2VubnkgTS4=?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    388
    =?Utf-8?B?S2VubnkgTS4=?=
    Apr 4, 2006
  4. CS
    Replies:
    2
    Views:
    1,371
    Esmond Pitt
    Jun 28, 2010
  5. CS
    Replies:
    3
    Views:
    603
    Kevin McMurtrie
    Jun 26, 2010
Loading...

Share This Page