List of usage examples for java.net InetAddress toString
public String toString()
From source file:net.wastl.webmail.misc.Helper.java
/** * Calculate session-ID for a session.// ww w . j a va 2 s . c om * * @param a Adress of the remote host * @param h Requestheader of the remote user agent * @returns Session-ID */ public static String calcSessionCode(InetAddress a, HTTPRequestHeader h) { String temp = a.toString().replace('\n', ' ') + h.getHeader("User-Agent").replace('\n', ' '); temp = "" + Long.toHexString(Math.abs(temp.hashCode())); if (h.getContent("login") != null && !h.getContent("login").equals("") && h.getPath().startsWith("/login")) { temp += Long.toHexString(Math.abs(h.getContent("login").hashCode())); temp += Long.toHexString(System.currentTimeMillis()); } else if (h.getPath().startsWith("/admin/login")) { temp += "admin"; } return temp; }
From source file:org.votingsystem.util.HttpHelper.java
public static String getLocalIP() throws SocketException { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { if (inetAddress.isSiteLocalAddress()) { String inetAddressStr = inetAddress.toString(); while (inetAddressStr.startsWith("/")) inetAddressStr = inetAddressStr.substring(1); return inetAddressStr; }/* w w w .ja v a 2s . c om*/ } } return null; }
From source file:org.apache.sshd.common.util.net.SshdSocketAddress.java
public static String toAddressString(InetAddress addr) { String ip = (addr == null) ? null : addr.toString(); if (GenericUtils.isEmpty(ip)) { return null; } else {//from w w w. j a v a 2 s .c o m return ip.replaceAll(".*/", ""); } }
From source file:com.vmware.aurora.global.Configuration.java
/** * Gets the fqdn of cms server. If it's not presented, the method tries to * retrieve the ip address of first network interface and reports it as the * fqdn./*from w w w .j a va 2s . c o m*/ * * @return The FQDN of CMS. */ public static String getCmsFQDN() { String fqdn = Configuration.getString("cms.mgmtnet.fqdn"); if (fqdn == null || fqdn.isEmpty()) { try { // try to retrieve the ip addr of eth0 NetworkInterface net = NetworkInterface.getByName("eth0"); Enumeration<InetAddress> addresses = net.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress addr = addresses.nextElement(); if (addr instanceof Inet4Address) { String ip = addr.toString(); fqdn = ip.substring(ip.lastIndexOf("/") + 1); break; } } } catch (Exception e) { logger.info("Error in retrieving ip of eth0", e); throw CommonException.INTERNAL(e); } } return fqdn; }
From source file:com.googlecode.networklog.NetworkLog.java
public static void getLocalIpAddresses() { MyLog.d("getLocalIpAddresses"); localIpAddrs = new ArrayList<String>(); try {//from ww w . ja v a2 s .co m for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); MyLog.d("Network interface found: " + intf.toString()); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); MyLog.d("InetAddress: " + inetAddress.toString()); if (!inetAddress.isLoopbackAddress()) { MyLog.d("Adding local IP address: [" + inetAddress.getHostAddress().toString() + "]"); localIpAddrs.add(inetAddress.getHostAddress().toString()); } } } } catch (SocketException ex) { Log.e("NetworkLog", ex.toString()); } }
From source file:org.smartfrog.test.unit.net.BasicNetworkingTest.java
/** * Log the address/*ww w . j a v a 2 s .com*/ * @param type address type * @param addr address value */ private void logAddr(String type, InetAddress addr) { log.info(type + ": " + addr.toString()); }
From source file:com.github.koraktor.steamcondenser.steam.servers.SourceServer.java
/** * Creates a new instance of a server object representing a Source server, * i.e. SrcDS instance/*from w w w . jav a 2 s .c o m*/ * * @param address Either an IP address, a DNS name or one of them * combined with the port number. If a port number is given, e.g. * 'server.example.com:27016' it will override the second argument. * @throws SteamCondenserException if initializing the socket fails */ public SourceServer(InetAddress address) throws SteamCondenserException { super(address.toString(), 27015); }
From source file:org.stem.StreamingTest.java
private void joinPseudoNode() throws ZooException { List<InetAddress> ipAddresses = Utils.getIpAddresses(); Map<UUID, MountPoint> mountPoints = new HashMap<UUID, MountPoint>(); UUID uuid = UUID.randomUUID(); mountPoints.put(uuid,/*from w w w . ja v a 2 s . c o m*/ new MountPoint(uuid, "/tmp/mp", (10l * 1024 * 1024 * 1024), new DataTracker(getvBucketsNum()))); JoinRequest req = new JoinRequest(); REST.StorageNode node = req.getNode(); node.setListen(StorageNodeDescriptor.getNodeListenAddress(), StorageNodeDescriptor.getNodeListenPort() + portIndex++); for (InetAddress ipAddress : ipAddresses) { node.getIpAddresses().add(ipAddress.toString()); } for (MountPoint mp : mountPoints.values()) { REST.Disk disk = new REST.Disk(mp.getId(), mp.getPath(), mp.getTotalSizeInBytes(), mp.getAllocatedSizeInBytes()); node.getDisks().add(disk); } clusterManagerClient.join(req, ZookeeperClientFactory.newClient("localhost:2180")); }
From source file:com.github.koraktor.steamcondenser.steam.servers.SourceServer.java
/** * Creates a new instance of a server object representing a Source server, * i.e. SrcDS instance//from w w w .j ava 2 s . c o m * * @param address Either an IP address, a DNS name or one of them * combined with the port number. If a port number is given, e.g. * 'server.example.com:27016' it will override the second argument. * @param port The port the server is listening on * @throws SteamCondenserException if initializing the socket fails */ public SourceServer(InetAddress address, Integer port) throws SteamCondenserException { super(address.toString(), port); }
From source file:com.smartdevicelink.tcpdiscovery.DiscoveredDevice.java
private String getLocalAddressForIface(String ifaceName) throws Exception { NetworkInterface iface = NetworkInterface.getByName(ifaceName); Enumeration<InetAddress> inetAddresses = iface.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { if (InetAddressUtils.isIPv4Address(inetAddress.toString())) { return inetAddress.toString(); }/* www . j a va2 s .co m*/ } return ""; }