Summary
This article describes how to retrieve the hostname and IP address of the target machine using a custom bean.Synopsis
Discussion
The values for hostname and IP address of the machine on which the install is running can be retrieved by writing a custom bean that uses the methods in the InetAddress class from the Java API. The following sample code demonstrates how this can be done within a custom wizard action.
import com.installshield.wizard.*;
import java.net.*;
public class FindHostName extends WizardAction {
public void execute(WizardBeanEvent event) {
try { /*Store the local host name into a JVM system property "localhost" */
System.setProperty("localhost.name", InetAddress.getLocalHost().getHostName());
System.setProperty("localhost.IP", InetAddress.getLocalHost().getHostAddress());
System.out.println("The hostname is "+System.getProperty("localhost.name")
+ "and the IP is "+System.getProperty("localhost.IP"));
} catch (UnknownHostException uh) { /* Print error message */
System.out.println("unknown host");
}
}
}
This code stores the hostname and IP address values in Java system properties named localhost.name and localhost.IP. These properties can be referred to in the bean properties of subsequent beans using the string resolver expressions
$J(localhost.name)
$J(localhost.IP)Additional Information
This example will not work correctly on systems with multiple network interfaces and/or multiple IP addresses. This is due to a limitation in Java's InetAddress class.
The Java2 version 1.4 API provides the class java.net.NetworkInterface, which has the static method getNetworkInterfaces() that allows the retrieval of information for all network interfaces present on a system. This API is safe to use in a custom bean provided that the setup is assured of running on a Java Virtual Machine of version 1.4 or higher. This can be specified by configuring the native distribution launcher to either search for or install a bundled 1.4.x JVM.
More information on the Java InetAdress and NetworkInterface classes can be found at the Sun Java API Web Site.
The article Network Programming with J2SE 1.4 on Sun's Java Web site contains good background information on the networking support provided in the Java2 version 1.4 API.
Related Articles
Agent communication using IPv6 IP address in beacon URL may fail with error "The URL is invalid" 1Number of Views IP address not reported by Columbus Inventory Agent 4Number of Views Retrieve and Display List of Machine Names and IP Addresses On Domain To User 4Number of Views Does Usage Intelligence Store the IP Address of Users? 3Number of Views Remote execution uses host names while "Attempt connection only by IP address" is checked for the target. 4Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Revenera Assistant
Case id: 00001065
Activity: Status change: 2 hours ago