网络参数

@echo 您的用户名是:%USERDOMAIN%\%username%>"%userprofile%\网络参数.txt"
@echo 您的机器名是:%COMPUTERNAME%>>"%userprofile%\网络参数.txt"
@echo ___________________>>"%userprofile%\网络参数.txt"
@echo 您的IP地址参数如下:>>"%userprofile%\网络参数.txt"
@ipconfig>>"%userprofile%\网络参数.txt"
@notepad "%userprofile%\网络参数.txt"
exit

利用多进程,调用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; } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值