1

I have created a Java Web Dynpro in the portal intranet. The localhost of the local machine is needed, but I'm only able to get the servername, serverlocalhost and the local machine ip-address.

When I'm running following code on a local java program, I'm getting:

  • Workstation: BEWSP
  • IP: 10.10.19.112

When I'm running following code on a SAP Portal program, I'm getting:

  • Workstation: SAPDEP
  • IP: 10.10.19.112

I need to get BEWSP in my SAP Portal application, any idea to do this?

           InetAddress ip = InetAddress.getLocalHost();
           String workstation = "";
           String currentip = "";
           //Workstation
           System.out.println("Workstation : " + ip.getHostName());
           workstation = "" + ip.getHostName();

           //Ip address
           System.out.println("Current IP address : " + ip.getHostAddress());
           currentip = "" +  ip.getHostAddress(); 

KR

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
user2206834
  • 379
  • 1
  • 5
  • 13
  • I'm not going to list this as an answer, because I've only had to deal with this on the Web Dynpro ABAP side. But, what I have to say may help. We were unable to make this work in WDA simply. Prior to release 7.03/7.31 and the introduction of HTML islands, we took the local machine IP and did a DNS lookup to get the hostname. After HTML Islands, we were able to touch the local machine, but in order to get the machine name we had to build a web service than ran on the target machine to get that info back to the application. Hope that at least points you in a helpful direction. – Bryan Cain Nov 29 '16 at 15:22
  • Thanks for the answer. I resolved my issue by doing a CMD-command (nslookup ) in my java code and picked the exact line with the name of the machine. After getting the appropriate line, a filtered the result with a regex to get the workstation name. – user2206834 Dec 08 '16 at 13:16
  • 'The localhost of the local machine' meaningless. The local machine is always `localhost` or `127.0.0.1`. If you mean its public DNS name or IP address please say so. – user207421 Aug 07 '19 at 01:30

1 Answers1

-1

Just to add the implementation of way chosen by OP:

import java.util.regex.Pattern;
import java.io.*;

public class nslookup
{
  public static void main(String[] args)
  {
      try {
                Process p = Runtime.getRuntime().exec("cmd /c nslookup 192.168.0.1");
                BufferedReader bi = new BufferedReader(new InputStreamReader(p.getInputStream()));
                String line = "";
                line = bi.readLine();
                while ( line != null ) {
                        if ( line.indexOf("Non-existent") != -1 ) {
                                System.out.println("The host/domain doesn't exist");
                                break;
                        }
                        if (line.matches("Server:\\s+.+$")) {
                            Matcher matcher = Pattern.compile("(Server:\\s+)([a-z0-9\\-]+[\\.]{1}[a-z0-9\\-]+([\\.]{1}[a-z0-9\\-]+)?([\\.]{1}[a-z0-9\\-]+)?)").matcher(line);
                            if (matcher.find()) {
                            String result = matcher.group(2);
                            System.out.println(result);
                            System.exit(42);
                            }
                        }
                        line = bi.readLine();
                }
                bi.close();
     } catch (IOException ioe) {
        ioe.printStackTrace(); }
  }
}
Suncatcher
  • 10,355
  • 10
  • 52
  • 90