简体   繁体   中英

What system environment stores the value of InetAddress.getLocalHost().GetCanonicalHostName()

I try to understand which system variables has this value. I execute this code and get some_string .

InetAddress.getLocalHost().GetCanonicalHostName();

After this I print all my system env

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

I find all variables which has some_string , and replace all value with

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

But my test failed

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

I finded that I need replace this ver:

"user.name", "user.home", "LOGONSERVER", "COMPUTERNAME", "USERDOMAIN_ROAMINGPROFILE", "USERDOMAIN", "COMPUTERNAME", "MACHINENAME";

But it don't help me too.

You can't set an environment variable to make Java think you are on a different machine. From java.lang.InetAddress -

Returns the address of the local host. This is achieved by retrieving the name of the host from the system, then resolving that name into an InetAddress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM