资源简介
C#获取局域网内所有联网设备的IP地址和MAC地址
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Collections;
using System.Diagnostics;
using System.IO;
namespace findDevice
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class LocalMachine
{
public string MachineIP { get; set; }
public string MachineMAC { get; set; }
public string MachineName { get; set; }
}
static ArrayList GetAllLocalMachines()
{
Process p = new Process();
p.StartInfo.FileName = “cmd.exe“;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(“arp -a“);
p.StandardInput.WriteLine(“exit“);
ArrayList list = new ArrayList();
StreamReader reader = p.StandardOutput;
for (string line = reader.ReadLine(); line != null; line = reader.ReadLine())
{
line = line.Trim();
if (line.StartsWith(“192“))
{
string IP = line.Substring(0 15).Trim();
string Mac = line.Substring(line.IndexOf(“-“) - 2 0x11).Trim();
LocalMachine localMachine = new LocalMachine();
localMachine.MachineIP = IP;
localMachine.MachineMAC = Mac;
if (IP.Equals(“192.168.0.1“)) continue;
//try
//{
// localMachine.MachineName = Dns.GetHostEntry(IP).HostName;
//}
//catch
//{
// localMachine.MachineName = ““;
// list.Add(localMachine);
// continue;
//}
list.Add(localMachine);
}
}
return list;
}
private void button1_Click(object sender EventArgs e)
{
textBox1.Text = “刷新列表“;
ArrayList ththth = GetAllLocalMachines();
if (ththth.Count == 0) return;
textBox1.Text = ““;
foreach (LocalMachine machine in ththth)
{
string s = string.Format(“{0} {1} {2}“ machine.MachineIP machine.MachineMAC machine.MachineName);
textBox1.Text = string.Format(“{0}{1}\r\n“ textBox1.Text s);
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10752 2013-02-02 16:53 FindNetDevices\findDevice\bin\Debug\findDevice.exe
文件 24064 2013-02-02 16:53 FindNetDevices\findDevice\bin\Debug\findDevice.pdb
文件 11600 2013-02-02 17:09 FindNetDevices\findDevice\bin\Debug\findDevice.vshost.exe
文件 490 2010-03-17 22:39 FindNetDevices\findDevice\bin\Debug\findDevice.vshost.exe.manifest
文件 3679 2013-02-02 15:30 FindNetDevices\findDevice\findDevice.csproj
文件 2984 2013-02-02 17:33 FindNetDevices\findDevice\Form1.cs
文件 2558 2013-02-02 16:11 FindNetDevices\findDevice\Form1.Designer.cs
文件 5817 2013-02-02 16:11 FindNetDevices\findDevice\Form1.resx
文件 2152 2013-02-02 15:27 FindNetDevices\findDevice\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6199 2013-02-02 16:53 FindNetDevices\findDevice\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 652 2013-02-02 17:09 FindNetDevices\findDevice\obj\x86\Debug\findDevice.csproj.FileListAbsolute.txt
文件 10752 2013-02-02 16:53 FindNetDevices\findDevice\obj\x86\Debug\findDevice.exe
文件 180 2013-02-02 16:15 FindNetDevices\findDevice\obj\x86\Debug\findDevice.Form1.resources
文件 24064 2013-02-02 16:53 FindNetDevices\findDevice\obj\x86\Debug\findDevice.pdb
文件 180 2013-02-02 15:30 FindNetDevices\findDevice\obj\x86\Debug\findDevice.Properties.Resources.resources
文件 220 2013-02-02 16:15 FindNetDevices\findDevice\obj\x86\Debug\GenerateResource.read.1.tlog
文件 550 2013-02-02 16:15 FindNetDevices\findDevice\obj\x86\Debug\GenerateResource.write.1.tlog
文件 491 2013-02-02 16:15 FindNetDevices\findDevice\Program.cs
文件 1370 2013-02-02 15:27 FindNetDevices\findDevice\Properties\AssemblyInfo.cs
文件 2870 2013-02-02 15:27 FindNetDevices\findDevice\Properties\Resources.Designer.cs
文件 5612 2013-02-02 15:27 FindNetDevices\findDevice\Properties\Resources.resx
文件 1095 2013-02-02 15:27 FindNetDevices\findDevice\Properties\Settings.Designer.cs
文件 249 2013-02-02 15:27 FindNetDevices\findDevice\Properties\Settings.settings
文件 872 2013-02-02 15:30 FindNetDevices\FindNetDevices.sln
..A..H. 20992 2013-02-02 17:09 FindNetDevices\FindNetDevices.suo
目录 0 2013-02-02 15:27 FindNetDevices\findDevice\obj\x86\Debug\TempPE
目录 0 2013-02-02 16:53 FindNetDevices\findDevice\obj\x86\Debug
目录 0 2013-02-02 15:30 FindNetDevices\findDevice\bin\Debug
目录 0 2013-02-02 15:27 FindNetDevices\findDevice\obj\x86
目录 0 2013-02-02 15:27 FindNetDevices\findDevice\bin
............此处省略8个文件信息
- 上一篇:C# UDP广播+委托+网络调试助手
- 下一篇:在WPF下的触摸屏键盘控件
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论