123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package com.yc.education.util;
- import java.io.IOException;
- import java.net.Inet4Address;
- import java.net.InetAddress;
- import java.net.InterfaceAddress;
- import java.net.NetworkInterface;
- import java.net.SocketException;
- import java.util.Enumeration;
- import java.util.List;
- public class MachineIp {
- /**
- * 获取本机Ip
- *
- * 通过 获取系统所有的networkInterface网络接口 然后遍历 每个网络下的InterfaceAddress组。
- * 获得符合 <code>InetAddress instanceof Inet4Address</code> 条件的一个IpV4地址
- * @return
- */
- @SuppressWarnings("rawtypes")
- public static String localIp() {
- String ip = null;
- Enumeration allNetInterfaces;
- try {
- allNetInterfaces = NetworkInterface.getNetworkInterfaces();
- while (allNetInterfaces.hasMoreElements()) {
- NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
- List<InterfaceAddress> InterfaceAddress = netInterface.getInterfaceAddresses();
- for (InterfaceAddress add : InterfaceAddress) {
- InetAddress Ip = add.getAddress();
- if (Ip != null && Ip instanceof Inet4Address) {
- ip = Ip.getHostAddress();
- }
- }
- }
- } catch (SocketException e) {
- e.printStackTrace();
- //logger.warn("获取本机Ip失败:异常信息:"+e.getMessage());
- }
- return ip;
- }
- public static void main(String[] args) throws IOException {
- /*System.err.println(localIp());*/
- SM4 sm4 = new SM4( );
- String decode = sm4.decode("pVUnxpFL39NMFFupXDwBdA==", "W5#");
- System.out.println(decode );
- }
- }
|