isReachable
Hi,
I am using isReachable to ping and check whether the ip address is already in use or not. I've no problem implementing the function in Windows. However, when I tried to run the same program in Linux(fedora 5) even after setting the setuid bit for java,
http://amazing-development.com/archives/2004/12/20/send-icmp-ping-in-java-15/
the program simply freeze. The isReachable never gets back a response of true or false, and the there are no errors or exceptions. I can't seem to find any other thread describing the same problem. My guess is that probably some of my setting is not set correctly. The program is running on java 1.6 and I post the code below for reference.publicclass JspinnerTestextends JDialog{
private JPanel contentPane;
private JTextField textField1;
private JButton searchPingableButton;
private JButton buttonOK;
/**
* Number of bytes in an ip address
*/
publicstaticfinalint MAX_SIZE = 4;
public JspinnerTest(){
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
searchPingableButton.addActionListener(new ActionListener(){
/**
* Invoked when an action occurs.
*/
publicvoid actionPerformed(ActionEvent e){
Pinger();
}
});
}
publicstaticvoid main(String[] args){
JspinnerTest dialog =new JspinnerTest();
dialog.pack();
dialog.setSize(100, 100);
dialog.setVisible(true);
System.exit(0);
}
privatevoid Pinger(){
Enumeration interfaces =null;
InetAddress ipAddress =null;
boolean isReachable =false;
try{
ipAddress = InetAddress.getByName(textField1.getText());
}catch (UnknownHostException e){
e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.
}
try{
interfaces = NetworkInterface.getNetworkInterfaces();
}catch (SocketException e){
e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.
}
assert interfaces !=null;
while (interfaces.hasMoreElements()){
NetworkInterface nextElement = (NetworkInterface) interfaces.nextElement();
try{
assert ipAddress !=null;
isReachable = ipAddress.isReachable(nextElement, 10, 5000);
}catch (IOException e){
e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.
}
if (isReachable){
System.out.println("Reached ipAddress" + ipAddress.getHostAddress() +"in interfaces" + nextElement.getDisplayName());
}
}
}
privatevoid createUIComponents(){
}
{
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
$$$setupUI$$$();
}
/**
* Method generated by IntelliJ IDEA GUI Designer
* >>> IMPORTANT!! <<<
* DO NOT edit this method OR call it in your code!
*
* @noinspection ALL
*/
privatevoid $$$setupUI$$$(){
contentPane =new JPanel();
contentPane.setLayout(new GridBagLayout());
final JPanel panel1 =new JPanel();
panel1.setLayout(new GridBagLayout());
GridBagConstraints gbc;
gbc =new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
contentPane.add(panel1, gbc);
final JPanel spacer1 =new JPanel();
gbc =new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel1.add(spacer1, gbc);
textField1 =new JTextField();
gbc =new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.anchor = GridBagConstraints.WEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel1.add(textField1, gbc);
searchPingableButton =new JButton();
searchPingableButton.setText("Search Pingable");
gbc =new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel1.add(searchPingableButton, gbc);
}
/**
* @noinspection ALL
*/
public JComponent $$$getRootComponent$$$(){return contentPane;}
}
Thanks

