惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
G
Google Developers Blog
B
Blog
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 叶小钗
The Cloudflare Blog
The Hacker News
The Hacker News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
雷峰网
雷峰网
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
量子位
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
H
Help Net Security
Help Net Security
Help Net Security
P
Palo Alto Networks Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
T
The Exploit Database - CXSecurity.com
Know Your Adversary
Know Your Adversary
Apple Machine Learning Research
Apple Machine Learning Research
Scott Helme
Scott Helme
N
News | PayPal Newsroom
AWS News Blog
AWS News Blog
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
腾讯CDC
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
GbyAI
GbyAI
Y
Y Combinator Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker

博客园 - 金鹏

独立的MySQL数据库需要做配置才能在外部访问到。 Visual Studio 2008简体中文试用版(90天)变成永久正式版的两种方法 [转]VisualSVN 1.5.x 破解方法详解 Zend Studio for Eclipse 环境搭建 巧设路由器 实现电信、网通南北互通 微软官方SQL Server 2008正式中文试用版下载 [转]如何循序渐进向DotNet架构师发展 [转]Asp.net中防止用户多次登录的方法 使用AJAX动态加栽JS脚本和CSS样式 [转]几种流行的AJAX框架jQuery,Mootools,Dojo,Ext JS的对比 [转]七年IT奋斗纪实及感悟 IE8的主页使用IE8访问居然也报JS错误 今天向四川汶川地震灾区捐献了100元,表达自己的心意. 绿豆蛙主题乐园 如何避免出现“终端服务器超出了最大允许连接数” 超越 —— 零点乐队 C# 2005 & .NET 3.0 高级编程(第5版) [转]解开最后期限的镣铐 性能问题依旧困扰着VS 2008
扫描局域网内电脑,并获得对应的MAC地址和主机名
金鹏 · 2008-08-29 · via 博客园 - 金鹏

代码如下:

using System;
using System.Net;
using System.Threading;

using System.Runtime.InteropServices;

namespace LocalIP {
  
class LanSearch {

    
/// <summary>
    
/// 取MAC地址
    
/// </summary>
    
/// <param name="DestIP">目标IP</param>
    
/// <param name="SrcIP">源IP</param>
    
/// <param name="pMacAddr">MAC地址</param>
    
/// <param name="PhyAddrLen">MAC地址的长度</param>
    
/// <returns></returns>

    [DllImport("iphlpapi.dll", ExactSpelling = true)]
    
private static unsafe extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);

    
/// <summary>
    
/// 在线程中扫描
    
/// </summary>

    private static void LanSearchThreadMethod() {
      
int i = Convert.ToUInt16(Thread.CurrentThread.Name);
      Console.Write(
".");

      
string strIP = "192.168.1." + i.ToString();

      
//IPHostEntry ip = null;
      IPAddress ip = null;
      
try {
        
//ip = Dns.GetHostEntry(strIP);
        ip = IPAddress.Parse(strIP);
      }

      
catch {
        
//Console.WriteLine("请勿输入非法IP地址");
        return;
      }


      
byte[] b = new byte[6];
      
int len = b.Length;
      
//int r = SendARP(BitConverter.ToInt32(ip.AddressList[0].GetAddressBytes(), 0), 0, b, ref len);
      int r = SendARP(BitConverter.ToInt32(ip.GetAddressBytes(), 0), 0, b, ref len);
      
int num = BitConverter.ToInt32(b, 0);
      
string mac = BitConverter.ToString(b, 06);

      
if (num != 0{//有效MAC
        
//Console.WriteLine("\r\n{0}--{1}--{2}", ip.AddressList[0].ToString(), ip.HostName, mac);
        Console.WriteLine("\r\n{0}--{1}", ip.ToString(), mac);
      }

    }


    
/// <summary>
    
/// 程序主入口
    
/// </summary>
    
/// <param name="args"></param>

    [STAThread]
    
static void Main(string[] args) {
      Thread[] thread 
= new Thread[255];
      ThreadStart threadMethod;

      
for (int i = 0; i < 255; i++{
        threadMethod 
= new ThreadStart(LanSearchThreadMethod);
        thread[i] 
= new Thread(threadMethod);
        thread[i].Name 
= i.ToString();
        thread[i].Start();
        
if (!thread[i].Join(100)) {
          thread[i].Abort();
        }

      }


      Console.WriteLine(
"\r\n按任意键返回");
      Console.ReadLine();
    }


  }

}