0

We are using Ubuntu machienes as our servers, such we got 14 servers.

The command ifconfig works on all terminals it gives specific IP address.

When I ran the following java program through a script, on one of the 14 servers I get the host ip as standard 127.0.0.1 (I uploaded this file and script on only 2 machines as of now)

package com;

import java.net.Inet4Address;

public class IpAddressTest {
    public static void main(String args[]) throws Exception {
        String ipaddress = Inet4Address.getLocalHost().getHostAddress();
        String hostname = Inet4Address.getLocalHost().getHostName();
        System.out.println("THE  IP ADDRESS IS" + ipaddress);
        System.out.println("THE  HOST NAME IS" + hostname);

    }
}

To test this program as which server will give me IP as 127.0.0.1, I need to upload this java class file and related script to execute that on all of the 14 servers.

Is there any other alternate way of finding that? I want to check if i can get the IP THROUGH java , but for this i need to upload these java file and script file to all 14 servers .so asking is there any alternate way 

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • 3
    What exactly do you want to accomplish? get the IP address of all 14 servers? why not a simple shell script? – Protostome Jun 27 '13 at 06:25
  • @Protostome yes correct i want to check if i can get the IP THROUGH java , but for this i need to upload these java file and script file to all 14 servers .so asking is there any alternate way –  Jun 27 '13 at 06:28
  • 3
    You do know that `127.0.0.1` is a loopback localhost address? All the machines would give you that address. I think you're looking to find the LAN IP but I guess your program isn't doing that. – Ravi K Thapliyal Jun 27 '13 at 06:33

1 Answers1

1

First, if you want to use Java, then you have to upload the classes and the script to every server.To find all the IP addresses: Get local IP-Address without connecting to the internet

Community
  • 1
  • 1
Balint Bako
  • 2,500
  • 1
  • 14
  • 13