本文整理汇总了Java中java.net.NetworkInterface.getDisplayName方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInterface.getDisplayName方法的具体用法?Java NetworkInterface.getDisplayName怎么用?Java NetworkInterface.getDisplayName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.NetworkInterface
的用法示例。
在下文中一共展示了NetworkInterface.getDisplayName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInductorIPv4Addr
import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
* Retruns the inductor IP address (IPV4 address). If there are multiple NICs/IfAddresses, it
* selects the first one. Openstack VMs normally has only one network interface (eth0).
*
* @return IPV4 address of inductor with interface name. Returns <code>null</code> if it couldn't
* find anything.
*/
private String getInductorIPv4Addr() {
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
while (nics.hasMoreElements()) {
NetworkInterface nic = nics.nextElement();
if (nic.isUp() && !nic.isLoopback()) {
Enumeration<InetAddress> addrs = nic.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress add = addrs.nextElement();
// Print only IPV4 address
if (add instanceof Inet4Address && !add.isLoopbackAddress()) {
// Log the first one.
String ip = add.getHostAddress() + " (" + nic.getDisplayName() + ")";
logger.info("Inductor IP : " + ip);
return ip;
}
}
}
}
} catch (Exception e) {
logger.warn("Error getting inductor IP address", e);
// Skip any errors
}
return null;
}
示例2: testAllNetworkInterfaces
import java.net.NetworkInterface; //导入方法依赖的package包/类
static void testAllNetworkInterfaces() throws Exception {
System.err.println("\n testAllNetworkInterfaces: \n ");
for (Enumeration<NetworkInterface> e = NetworkInterface
.getNetworkInterfaces(); e.hasMoreElements();) {
NetworkInterface netIF = e.nextElement();
// Skip (Windows)Teredo Tunneling Pseudo-Interface
if (isWindows) {
String dName = netIF.getDisplayName();
if (dName != null && dName.contains("Teredo")) {
continue;
}
}
for (Enumeration<InetAddress> iadrs = netIF.getInetAddresses(); iadrs
.hasMoreElements();) {
InetAddress iadr = iadrs.nextElement();
if (iadr instanceof Inet6Address) {
System.err.println("Test NetworkInterface: " + netIF);
Inet6Address i6adr = (Inet6Address) iadr;
System.err.println("Testing with " + iadr);
System.err.println(" scoped iface: "
+ i6adr.getScopedInterface());
testInet6AddressSerialization(i6adr, null);
}
}
}
}
示例3: isIncluded
import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
* Check if the input network interface should be included in the test. It is necessary to exclude
* "Teredo Tunneling Pseudo-Interface" whose configuration can be variable during a test run.
*
* @param ni a network interace
* @return false if it is a "Teredo Tunneling Pseudo-Interface", otherwise true.
*/
private boolean isIncluded(NetworkInterface ni) {
if (!IS_WINDOWS) {
return true;
}
String dName = ni.getDisplayName();
return dName == null || !dName.contains("Teredo");
}
示例4: isNotExcludedInterface
import java.net.NetworkInterface; //导入方法依赖的package包/类
private static boolean isNotExcludedInterface(NetworkInterface nif) {
if (Platform.isOSX() && nif.getName().contains("awdl")) {
return false;
}
String dName = nif.getDisplayName();
if (Platform.isWindows() && dName != null && dName.contains("Teredo")) {
return false;
}
return true;
}
示例5: getHWSeq
import java.net.NetworkInterface; //导入方法依赖的package包/类
static private long getHWSeq()
{
if (hwseq != 0)
return hwseq;
for (int ii = 0; ii < 50; ii++)
{
try
{
NetworkInterface ni = NetworkInterface.getByIndex(ii);
if (ni != null) // real interface
{
byte[] hwaddr = ni.getHardwareAddress();
if (hwaddr == null) continue;
String dname = ni.getDisplayName();
if (dname.startsWith("Microsoft")) continue;
if (dname.startsWith("VMware")) continue;
if (dname.startsWith("VirtualBox")) continue;
if (dname.contains("Tunneling")) continue;
// HW will be somewhat unique, we use the above to skip things that generally are not
hwseq = (VARIANT1 & VARIANT_MASK)| (new Random().nextLong() & CLKSEQ_MASK) | (new BigInteger(1, hwaddr).longValue() & NODE_MASK);
break;
}
}
catch (SocketException se) {}
}
return hwseq;
}
示例6: getStatus
import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
* Method to return status of the firewall.
* Status can be retrieved over REST API.
*
*/
public static String getStatus() {
String s = "";
s += "Jetty Server Status = " + jettyServer.getState() + "\n";
s += "Jetty Date = " + jettyServer.getDateField().toString() + "\n";
s += "Jetty URI = " + jettyServer.getURI().toString() + "\n";
s += "\n";
s += "SCTP Associations\n";
for (Map.Entry<String, Association> a : sctpManagement.getAssociations().entrySet()) {
s += " Name = " + a.getKey() + "\n";
s += " Details = " + a.getValue().toString() + "\n";
s += " isStarted = " + a.getValue().isStarted() + "\n";
s += " isConnected = " + a.getValue().isConnected() + "\n";
}
s += "\n";
s += "SCTP Servers = " + sctpManagement.getServers().toString() + "\n";
s += "\n";
s += "OS statistics\n";
s += " Available processors (cores): " + Runtime.getRuntime().availableProcessors() + "\n";
s += " Free memory (bytes): " + Runtime.getRuntime().freeMemory() + "\n";
long maxMemory = Runtime.getRuntime().maxMemory();
s += " Maximum memory (bytes): " + (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory) + "\n";
s += " Total memory available to JVM (bytes): " + Runtime.getRuntime().totalMemory() + "\n";
File[] roots = File.listRoots();
/* For each filesystem root, print some info */
for (File root : roots) {
s += " File system root: " + root.getAbsolutePath() + "\n";
s += " Total space (bytes): " + root.getTotalSpace() + "\n";
s += " Free space (bytes): " + root.getFreeSpace() + "\n";
s += " Usable space (bytes): " + root.getUsableSpace() + "\n";
}
s += "\n";
s += "Network interfaces\n";
try {
Enumeration<NetworkInterface> nets;
nets = NetworkInterface.getNetworkInterfaces();
for (NetworkInterface netint : Collections.list(nets)) {
s += " Display name: " + netint.getDisplayName() + "\n";
s += " Name: " + netint.getName() + "\n";
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
for (InetAddress inetAddress : Collections.list(inetAddresses)) {
s += " InetAddress: " + inetAddress + "\n";
}
}
} catch (SocketException ex) {
java.util.logging.Logger.getLogger(DiameterFirewall.class.getName()).log(Level.SEVERE, null, ex);
}
return s;
}