您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 查看本机网络信息
  所属分类: 网络监控
  开发工具:
  文件大小: 5kb
  下载次数: 0
  上传时间: 2012-03-03
  提 供 者: erp***
 详细说明: 利用多进程,调用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(cmd); } 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("nbtstat -A " + remotePcIP); 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("ipconfig /all"); 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("ipconfig /all"); 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("ipconfig /all"); 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; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: java
 输入关键字,在本站1000多万海量源码库中尽情搜索: