自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (2)
  • 收藏
  • 关注

空空如也

查看本机网络信息

利用多进程,调用DOS命令查看网络信息 public class ipconfig extends JFrame{ static TextField ip_text=new TextField(15); static TextField mac_text=new TextField(15); static TextField subnetmask_text=new TextField(15); static TextField gateway_text=new TextField(15); static TextField dns_text=new TextField(15); static JPanel subnetmask=new JPanel(new FlowLayout()); static JPanel gateway=new JPanel(new FlowLayout()); static JPanel IP=new JPanel(new FlowLayout()); static JPanel dns=new JPanel(new FlowLayout()); public static void main(String[] args) throws UnknownHostException { ipconfig f=new ipconfig(); f.setTitle("查看本机网络设置QQ125004485"); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocation(400,400); f.setSize(new Dimension(200,300)); // gotoUrlWindows("http://ygsn.taobao.com/"); //gotoUrlWindows("www.sohu.com"); f.setResizable(false); f.setLayout(new GridLayout(6,1)); //IP文本框 setCFont(IP); IP.add(new Label("IP:")); IP.add(ip_text); ip_text.setText(getLocalIp()); //MAC 文本框 JPanel MAC=new JPanel(new FlowLayout()); setCFont(MAC); MAC.add(new Label("MAC:")); MAC.add(mac_text); mac_text.setText(getMacAddressIP(ip_text.getText())); //子网掩码 setCFont(subnetmask); subnetmask.add(new Label("子网掩码:")); subnetmask.add(subnetmask_text); subnetmask_text.setText(getSubnetMask()); //网关 setCFont(gateway); gateway.add(new Label("网关:")); gateway.add(gateway_text); gateway_text.setText(getGateWay()); //DNS setCFont(dns); dns.add(new Label("DNS:")); dns.add(dns_text); dns_text.setText(getDns()); //加载文本框 f.add(subnetmask); f.add(MAC); f.add(IP); f.add(gateway); f.add(dns); f.pack(); } // Windows platform goto url private static void gotoUrlWindows(String url){ String cmd = "rundll32 url.dll,FileProtocolHandler " + url; try { Runtime.getRuntime().exec&#40;cmd&#41;; } catch (IOException e) { e.printStackTrace(); } } //取IP private static String getLocalIp() throws UnknownHostException { return InetAddress.getLocalHost().getHostAddress(); } //设置字体 private static void setCFont(Container c) { c.setFont(new Font( "宋体 ",Font.BOLD,15)); } public static String getMacAddressIP(String remotePcIP) { String str = ""; String macAddress = ""; try { Process pp = Runtime.getRuntime().exec&#40;"nbtstat -A " + remotePcIP&#41;; InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf("MAC Address") > 1) { macAddress = str.substring( str.indexOf("MAC Address") + 14, str.length()); break; } } } } catch (IOException ex) { } return macAddress; } public static String getSubnetMask() { String str = ""; String subnetmask = ""; try { Process pp = Runtime.getRuntime().exec&#40;"ipconfig /all"&#41;; InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf("Subnet Mask") > -1) { subnetmask = str.substring( str.indexOf("Subnet Mask") + 36, str.length()); break; } } } } catch (IOException ex) { } return subnetmask; } public static String getGateWay() { String str = ""; String gateway = ""; try { Process pp = Runtime.getRuntime().exec&#40;"ipconfig /all"&#41;; InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf("Default Gateway") > -1) { gateway = str.substring( str.indexOf("Default Gateway") + 36, str.length()); break; } } } } catch (IOException ex) { } return gateway; } public static String getDns() { String str = ""; String dns = ""; try { Process pp = Runtime.getRuntime().exec&#40;"ipconfig /all"&#41;; InputStreamReader ir = new InputStreamReader(pp.getInputStream()); LineNumberReader input = new LineNumberReader(ir); for (int i = 1; i < 100; i++) { str = input.readLine(); if (str != null) { if (str.indexOf("DNS Servers") > -1) { dns = str.substring( str.indexOf("DNS Servers") + 36, str.length()); break; } } } } catch (IOException ex) { } return dns; } }

2012-03-03

常用软件包

利用多进程,托盘管理,类开发的。大家可以学习一下,也可以在此基础上,进一步的开发。

2012-02-23

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除