留待以后观看

————————————————————————————————————————————————————————————————————————————

public class IP_MAC_TypeHelper {

	/**
* 控制台执行arp -a命令
*
* @return
*
*/
public static InputStream getInputStream() {
Runtime rt = Runtime.getRuntime();
InputStream in = null;
try {
Process p = rt.exec("cmd.exe /c arp -a");
in = p.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return in; } /**
* 获取的字节流转成String
*
* @param in
* @return
*/
public static String read(InputStream in) {
InputStreamReader isr;
try {
isr = new InputStreamReader(in, "GBK");
BufferedReader br = new BufferedReader(isr);
String inline = null;
StringBuffer sb = new StringBuffer();
while ((inline = br.readLine()) != null) {
// System.out.println(inline);
sb.append(inline);
}
return sb.toString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null; } /**
* 格式化输出信息
*
* @param msg
* @return
*/
public static String[] getMsg(String msg) {
//按换行截取
String[] tempmessage = msg.split("\r\n");
StringBuffer sb = new StringBuffer();
for (String s : tempmessage) {
sb.append(s + " ");
}
String temp = sb.toString();
return temp.split(" {1,}");
} /**
* 截取IP地址信息
*
* @param msg
* @return
*/
public static List<String> getIp(String[] msg) {
List<String> list = new ArrayList<String>();
for (String s : msg) {
boolean flag = s.matches("^[0-9]{1,3}(\\.[0-9]{1,3}){3}$");// 匹配IP的正则
if (flag) {
list.add(s);
}
}
return list;
} /**
* 截取MAC地址信息
*
* @param msg
* @return
*/
public static List<String> getMac(String[] msg) {
List<String> list = new ArrayList<String>();
String regx = "^[a-zA-Z0-9]{2}(-[a-zA-Z0-9]{2}){5}$"; // 匹配MAC地址的正则
for (String s : msg) {
if (s.matches(regx)) {
list.add(s);
}
}
return list;
} /**
* 截取类型信息
*
* @param msg
* @return
*/
public static List<String> getType(String[] msg) { List<String> list = new ArrayList<String>();
for (String s : msg) {
if (s.contains("态")) { // 判断是否为指定字符
list.add(s);
}
}
return list; } /**
* 移除本机IP(包含网卡)
* @param ipList
* @return
*/
public static List<String> removeLocalIp(List<String> ipList) {
List<String> ripList = new ArrayList<String>();
try {
Enumeration<NetworkInterface> netInterfaces = NetworkInterface
.getNetworkInterfaces();
while (netInterfaces.hasMoreElements()) {
NetworkInterface nif = netInterfaces.nextElement();
Enumeration<InetAddress> iparray = nif.getInetAddresses();
while (iparray.hasMoreElements()) {
/*
* System.out.println("IP:" +
* iparray.nextElement().getHostAddress());
*/
ripList.add(iparray.nextElement().getHostAddress());
}
} } catch (Exception e) {
System.out.println(e.getMessage());
}
for (int i = 0; i < ipList.size() - 1; i++) {
for (String rip : ripList) {
if (ipList.get(i).equals(rip)) {
ipList.remove(i);
}
}
}
return ipList;
} /**
* 获取对应的IP、MAC、类型
* @return
*/
public static List<Admin> getIp_Mac_Type() {
List<Admin> aList = new ArrayList<Admin>();
InputStream in = getInputStream();
String message = read(in);
String[] msg = getMsg(message);
List<String> list_ip = removeLocalIp(getIp(msg));
List<String> list_mac = getMac(msg);
List<String> list_type = getType(msg);
for(int i = 0; i<list_ip.size(); i++){
Admin admin = new Admin();
admin.setIp(list_ip.get(i));
admin.setMac(list_mac.get(i));
admin.setType(list_type.get(i));
aList.add(admin);
}
for(Admin a:aList){
System.out.println(a.getIp());
}
return aList;
} }

我们知道在cmd命令行窗口中输入arp -a能得到局域网下所有IP,上述代码调用该命令得到所有IP,以上仅为借鉴。有待完善。。。

————————————————————————————————————————————————————————

版权所有,出自http://www.cnblogs.com/ytlds

调用cmd命令行命令(借鉴)的更多相关文章

  1. system调用命令行命令而不显示命令行窗口

    system调用命令行命令而不显示命令行窗口 通常用system调用命令行命令时都会弹出黑底白字的命令行窗口,下面的代码可以不显示弹出的命令行窗口. 代码如下 #pragma comment( lin ...

  2. C/C++ 程序中调用命令行命令并获取命令行输出结果

    在 c/c++ 程序中,可以使用 system()函数运行命令行命令,但是只能得到该命令行的 int 型返回值,并不能获得显示结果.例如system(“ls”)只能得到0或非0,如果要获得ls的执行结 ...

  3. Windows命令行命令集锦

    原文:Windows命令行命令集锦 转自:http://www.me2wg.com/bbs/forum.php?mod=viewthread&tid=15830 winver--------- ...

  4. MySql命令行命令和SQL语句

    一.常用mysql命令行命令 1.启动MYSQL服务 net start mysql 停止MYSQL服务 net stop mysql 2.netstat -na|findstr 3306 查看被监听 ...

  5. iOS工程师常用的命令行命令总结

    感觉有点标题党了. 作为一个iOS工程师,没有做过服务端,主要用的是mac电脑,此篇博文是记录我在工作,学习的过程中用的命令行命令的记录和归纳总结 一. mac命令行 1. cd /Users/xxx ...

  6. Windows与Linux的命令行命令对比

    Windows与Linux的命令行命令对比 * Windows不区分大小写,Linux区分大小写的. sn DOS Command UNIX Equivalent Effect 影响 1 ASSIGN ...

  7. 一些坑 Java 执行命令行命令 Spring Boot 打包为jar ResourceUtils.getFile 等出现的问题

    Java 执行命令行命令 这个没技术含量的东西耗费了我半个多小时 String command = ....; Process process = Runtime.getRuntime().exec( ...

  8. [转帖]Windows与Linux的命令行命令对比

    Windows与Linux的命令行命令对比 https://www.cnblogs.com/sztom/p/10785140.html * Windows不区分大小写,Linux区分大小写的. sn ...

  9. 我自己总结的sqlite的命令行命令集

    我自己总结的sqlite 的命令行命令 导入文本数据文件时,设置分隔符为","sql>.separator "," sql>import devic ...

随机推荐

  1. 阶段2-新手上路\项目-移动物体监控系统\Sprint4-嵌入式web服务器开发\第3课-CGI程序开发

    实现CGI程序显示一幅图片最核心的功能 把上一节课编写好的led.c程序拷贝过来,并重新命名为image.c 把led的某些部分删除,后如下 那么如何显示一幅图片呢,百度(搜索在html里面去插入图片 ...

  2. .NET中的泛型委托

    .Net中有一个内置的委托 Func 它总共有以下5种形式 1.  Func<TResult> 2.  Func<T,TResult> 3.  Func<T1,T2,TR ...

  3. hdu1055

    #include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #inc ...

  4. 网页游戏开发秘笈 PDF扫描版

    精选10种常见的游戏类型,透过典型实例,深入剖析游戏引擎及工具的选用技巧,详细讲解每款游戏的制作过程,为快速掌握网页游戏开发提供系统而实用的指南. 网页游戏开发秘笈 目录: 译者序  前 言  导 言 ...

  5. EasyUI 在mvc中的引入与使用

    使用步骤: 一.先引入: 1.easyui下载,可以去官方网站去下载最新版EasyUI官方下载地址:http://www.jeasyui.com/download/index.php 2.下载后解压, ...

  6. .txt文件转换到Excel

    背景    前几天,自己在实验室里做实验,我们的大偶像肖老师看见我了,把我宣到他的办公室,问我,这个怎么办.都是数字,两列数字,怎么排版到Excel上也显示两列数字.Oh My God! 这个我怎么知 ...

  7. MCP|DYM|Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenocarcinoma and validate a novel somatic mutation CDK12-G879V (利用定量质谱探究转移性肺腺瘤的蛋白质组异质性及验证新体细胞突变)

    文献名:Quantitative mass spectrometry to interrogate proteomic heterogeneity in metastatic lung adenoca ...

  8. K8S上的ELK和应用日志上报实战

    来源:DevOps ID:Idevops168 本次实战的基础结构如下图所示: 一共有两个Pod:ELK和web应用: ELK的Pod会暴露两个服务,一个暴露logstash的5044端口,给file ...

  9. springBoot2.0 配置 mybatis+mybatisPlus+redis

    一.Idea新建springBoot项目 next到完成,然后修改使用自己的maven 等待下载包 二.pom.xml文件 <?xml version="1.0" encod ...

  10. css3中的变形(transform)、过渡(transtion)、动画(animation)

    Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一 ...