java 积累资料

1.java lookandfeel获得本地系统的UI风格

 

try{

   String lookAndFeel = javax.swing.UIManager.getSystemLookAndFeelClassName();
   UIManager.setLookAndFeel(lookAndFeel);

}catch(Exception e){

     e.printStackTrace();

}

 

2.java获得操作系统类型

 

String osName = (String) AccessController.doPrivileged(
                new GetPropertyAction("os.name"));
System.out.println("操作系统为:" + osName);

 

3.java判断ip地址

 

Pattern pattern = Pattern.compile( "^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$" );   

return pattern.matcher( str ).matches();

 

4.java获取系统IP地址和MAC地址

 

package cn.com.test;   

  

import java.io.BufferedReader;   

import java.io.IOException;   

import java.io.InputStreamReader;   

  

public class CCSFDs {   

    public static void main(String[] args) throws Exception {   

           

        String osname = System.getProperty("os.name");   

        System.out.println("你的操作系统是" + osname);   

        System.out.println("你的IP是" + getWIndowsIp());   

        System.out.println("你的mac地址 " + getLocalWindowsMAC());   

  

    }   

  

    private static String getLocalWindowsMAC() throws Exception {   

        Runtime rt = Runtime.getRuntime();   

        Process process = rt.exec("ipconfig /all");   

        BufferedReader in = new BufferedReader(new InputStreamReader(process   

                .getInputStream()));   

        String s;   

        while ((s = in.readLine()) != null) {   

            s = s.trim();   

            if (s.startsWith("Physical Address")) {   

                s = s.substring("Physical Address".length()).trim();   

                int pos = s.indexOf(": ");   

              if (pos > -1) {   

                    String mac = s.substring(pos + ": ".length()).trim();   

                    return mac;   

                }   

            }   

        }   

        return null;   

    }   

    private static String getWIndowsIp(){   

        String ip ="";   

        Runtime rt = Runtime.getRuntime();   

        Process process = null;   

        try {   

            process = rt.exec("ipconfig /all");   

            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));   

            String s;   

            while ((s = in.readLine()) != null) {   

                s = s.trim();   

                if (s.startsWith("IP Address")) {   

                    s = s.substring("IP Address".length()).trim();   

                    int pos = s.indexOf(": ");   

                    if (pos > -1) {   

                        ip = s.substring(pos + ": ".length()).trim();   

                    }   

                }   

            }   

        } catch (IOException e) {   

            e.printStackTrace();   

        }   

        return ip;   

    }   

}

 

5.java获取linux操作系统的网卡信息(包括名称.....)

  

public class NetworkParameterDemo {

  public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = en.nextElement();
      printParameter(ni);
  
    }
  }
  
  public static void printParameter(NetworkInterface ni) throws SocketException {
    System.out.println(" Name = " + ni.getName());
    System.out.println(" Display Name = " + ni.getDisplayName());
    System.out.println(" Is up = " + ni.isUp());
    System.out.println(" Support multicast = " + ni.supportsMulticast());
    System.out.println(" Is loopback = " + ni.isLoopback());
    System.out.println(" Is virtual = " + ni.isVirtual());
    System.out.println(" Is point to point = " + ni.isPointToPoint());
    System.out.println(" Hardware address = " + ni.getHardwareAddress());
    System.out.println(" MTU = " + ni.getMTU());
  
    System.out.println("\nList of Interface Addresses:");
    List<InterfaceAddress> list = ni.getInterfaceAddresses();
    Iterator<InterfaceAddress> it = list.iterator();
  
    while (it.hasNext()) {
      InterfaceAddress ia = it.next();
      System.out.println(" Address = " + ia.getAddress());
      System.out.println(" Broadcast = " + ia.getBroadcast());
      System.out.println(" Network prefix length = " + ia.getNetworkPrefixLength());
      System.out.println("");
    }
  }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值