List of usage examples for java.net SocketException printStackTrace
public void printStackTrace()
From source file:Main.java
public static String getIPAddr() { try {//from w w w . j a va 2s. c o m Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); return inetAddress.getHostAddress().toString(); } } } catch (SocketException e) { e.printStackTrace(); } return null; }
From source file:com.common.utils.NetworkUtils.java
public static String getLocalHostIp() { String ips = "";//getString(R.string.ipaddr); try {/* w ww . j a va 2 s . com*/ Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface nif = en.nextElement(); Enumeration<InetAddress> inet = nif.getInetAddresses(); while (inet.hasMoreElements()) { InetAddress ip = inet.nextElement(); if (!ip.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip.getHostAddress())) { ips = ips + nif.getName() + ":" + ip.getHostAddress() + " "; } } } } catch (SocketException e) { e.printStackTrace(); } return ips; }
From source file:Main.java
public static String getWifiMac(Context context) { String macAddr;/*from w w w. ja v a 2 s .c o m*/ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); macAddr = wifiInfo.getMacAddress(); if (TextUtils.isEmpty(macAddr)) { NetworkInterface networkInterface = null; try { networkInterface = NetworkInterface.getByInetAddress(InetAddress.getByName(getIPAddr())); byte[] hardwareAddress = networkInterface.getHardwareAddress(); macAddr = byte2hex(hardwareAddress); } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } } return macAddr; }
From source file:com.netsteadfast.greenstep.util.HostUtils.java
public static String getHostAddress() { String hostAddress = ""; try {/* w w w . j a v a 2s .c o m*/ Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); for (; nics.hasMoreElements() && "".equals(hostAddress);) { NetworkInterface interfece = nics.nextElement(); if (interfece.getName().toLowerCase().startsWith("lo")) { continue; } Enumeration<InetAddress> addrs = interfece.getInetAddresses(); for (; addrs.hasMoreElements() && "".equals(hostAddress);) { InetAddress addr = addrs.nextElement(); if (addr.getHostAddress().indexOf(":") > -1) { continue; } hostAddress = addr.getHostAddress(); } } } catch (SocketException e) { e.printStackTrace(); } if (StringUtils.isBlank(hostAddress)) { hostAddress = "127.0.0.1"; } return hostAddress; }
From source file:Main.java
public static String getHostIP() { String hostIp = null;/*from w ww.j a v a 2s. co m*/ try { Enumeration nis = NetworkInterface.getNetworkInterfaces(); InetAddress ia = null; while (nis.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) nis.nextElement(); Enumeration<InetAddress> ias = ni.getInetAddresses(); while (ias.hasMoreElements()) { ia = ias.nextElement(); if (ia instanceof Inet6Address) { continue;// skip ipv6 } String ip = ia.getHostAddress(); if (!"127.0.0.1".equals(ip)) { hostIp = ia.getHostAddress(); break; } } } } catch (SocketException e) { Log.i("yao", "SocketException"); e.printStackTrace(); } return hostIp; }
From source file:com.vish.phishDetect.Web_Utilities.java
public static int domainAge(String domainName) { StringBuilder whoisResult = new StringBuilder(""); WhoisClient crunchifyWhois = new WhoisClient(); try {/*from w w w.ja v a 2 s . co m*/ // The WhoisClient class implements the client side of the Internet // Whois Protocol defined in RFC 954. To query a host you create a // WhoisClient instance, connect to the host, query the host, and // finally disconnect from the host. If the whois service you want // to query is on a non-standard port, connect to the host at that // port. crunchifyWhois.connect(WhoisClient.DEFAULT_HOST); String whoisData = crunchifyWhois.query("=" + domainName); whoisResult.append(whoisData); crunchifyWhois.disconnect(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String patternString1 = "No\\smatch\\sfor"; Pattern pattern = Pattern.compile(patternString1); Matcher matcher = pattern.matcher(whoisResult); if (!matcher.find()) { System.out.println(domainName + "\n" + whoisResult); } return 0;//whoisResult.toString(); }
From source file:org.cnbi.utils.license.MacAddressUtil.java
/** * IP??Mac?/*from w w w .j a va2 s . com*/ * * @param ia * @return */ private static String getMacByIpAddress(InetAddress ia) { // ???mac?mac?byte try { byte[] mac = NetworkInterface.getByInetAddress(ia).getHardwareAddress(); // System.out.println("mac" + mac.length); // ??mac??String StringBuffer sb = new StringBuffer(""); for (int i = 0; i < mac.length; i++) { if (i != 0) { sb.append(":"); } // mac[i] & 0xFF byte int temp = mac[i] & 0xff; String str = Integer.toHexString(temp); // System.out.println("?8?:" + str); if (str.length() == 1) { sb.append("0" + str); } else { sb.append(str); } } // ???mac? return sb.toString().toUpperCase(); } catch (SocketException e) { e.printStackTrace(); return getMacByCommand(); } }
From source file:com.frostwire.util.VPNs.java
public static void printNetworkInterfaces() { try {// w ww. j av a2 s . co m Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface iface = networkInterfaces.nextElement(); System.out.println(iface.getIndex() + ":" + iface.getDisplayName() + ":" + "virtual=" + iface.isVirtual() + ":" + "mtu=" + iface.getMTU() + ":mac=" + (iface.getHardwareAddress() != null ? "0x" + ByteUtils.encodeHex(iface.getHardwareAddress()) : "n/a")); } } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.talend.commons.utils.network.NetworkUtil.java
public static boolean isSelfAddress(String addr) { if (addr == null || addr.isEmpty()) { return false; // ? }//w ww.j a v a2 s. co m try { final InetAddress sourceAddress = InetAddress.getByName(addr); if (sourceAddress.isLoopbackAddress()) { // final String hostAddress = sourceAddress.getHostAddress(); // // if addr is localhost, will be 127.0.0.1 also // if (hostAddress.equals("127.0.0.1") || hostAddress.equals("localhost") ) { return true; // } } else { // check all ip configs InetAddress curAddr = null; Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces(); while (netInterfaces.hasMoreElements()) { NetworkInterface ni = netInterfaces.nextElement(); Enumeration<InetAddress> address = ni.getInetAddresses(); while (address.hasMoreElements()) { curAddr = address.nextElement(); if (addr.equals(curAddr.getHostAddress())) { return true; } } } } } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } return false; }
From source file:com.cats.version.utils.Utils.java
public static String getLocalHostIp() { String regex = "[\\d]+.[\\d]+.[\\d]+.[\\d]+"; Enumeration<?> e = null; try {/* ww w.j a va 2 s .c om*/ e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); } while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<?> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); String ip = i.getHostAddress(); if (ip.matches(regex) && !ip.equals("127.0.0.1")) { return ip; } } } return null; }