Broadcasting but not getting all the machine in the network

B

BigZero

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
 
M

Mark Space

BigZero said:
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?
 
B

BigZero

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
 
M

Mark Space

BigZero said:
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?
 
N

Nigel Wade

BigZero said:
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.
 
B

BigZero

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
 
B

BigZero

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

what is this ?








Thanks
Vijay
 
N

Nigel Wade

BigZero said:
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.
 
R

RedGrittyBrick

BigZero said:
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
 
B

BigZero

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top