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
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