1

我在门户内网中创建了一个 java webdynpro。需要本地机器的 localhost,但我只能获取 servername、serverlocalhost 和本地机器 ip-address。

当我在本地 java 程序上运行以下代码时,我得到: 工作站:BEWSP IP: 10.10.19.112

当我在 SAP Portal 程序上运行以下代码时,我得到: 工作站:SAPDEP IP: 10.10.19.112

我需要在我的 SAP Portal 应用程序中获取 BEWSP,有什么想法吗?

           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(); 

韩国

4

1 回答 1

0

只是添加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(); }
  }
}
于 2019-08-06T22:57:51.753 回答