0

I am trying this code in order to ping that ip address in LAN.. the result return is Sorry.

thanks. if u help me

I want to ping that ip of a printer from my device. can i do this.

 String ip_address="\\10.28.81.9";
 boolean reachable=false;  
 TextView txt=(TextView) findViewById(R.id.info);
 InetAddress address;
try {
    address = InetAddress.getByName(ip_address);
    reachable =address.isReachable(3000); 
} catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}  
        if(reachable){
            txt.setText("Got it");
        }else{
            txt.setText("Sorry");

        }
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Jaffar Raza
  • 176
  • 3
  • 10

1 Answers1

0

Try removing the \'s at the begining of the address.

John Allen
  • 159
  • 4
  • address = InetAddress.getByName(ip_address); is a problem as it is doing a forward lookup, and you are providing an address. You need to use getByAddress(String host, byte[] addr) – John Allen Jan 11 '12 at 15:43