哪个系统环境存储InetAddress.getLocalHost().GetCanonicalHostName()的值



我试图了解哪些系统变量具有此值。我执行此代码并获得some_string

InetAddress.getLocalHost((.GetCanonicalHostName((;

在此之后,我打印所有的系统环境

System.getenv((.forEach((k,v(->System.out.println("K="+K+";V="+"v( (;

我找到所有具有some_string的变量,并用替换所有值

@ClassRule
public final static EnvironmentVariables ENVIRONMENT_VARIABLES = new EnvironmentVariables();
final String pcNameForEnv = "test-pc-name";
ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv);

但我的测试未通过

@Test
public void getMachineNameFromEnv() {
final String pcNameForEnv = "test-pc-name";
ENVIRONMENT_VARIABLES.set("USERDOMAIN", pcNameForEnv);
final String machineName = networkUtil.getPCNetworkName();
assertEquals(pcNameForEnv, machineName);
}

我发现我需要更换这个ver:

"用户名";,"user.home";,"LOGONSERVER";,"COMPUTERNAME";,"USERDOMAIN_ROAMINGPROFILE";,"USERDOMAIN";,"COMPUTERNAME";,"MACHINENAME";;

但这对我也没有帮助。

您不能设置环境变量来让Java认为您在另一台机器上。来自java.lang.InetAddress-

返回本地主机的地址。这是通过从系统中检索主机的名称,然后将该名称解析为InetAddress来实现的。

相关内容

  • 没有找到相关文章

最新更新