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

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 35号房客

从Window共享服务器上注销登陆 MDK 10.1版,简单硬盘安装法(图形界面) ORACLE_SID在Linux平台是否大小敏感?是! oracle 9i on redhat as3,应该安装的rpm start isqlplus&em of oracle 通过ftp修改帐户密码 学会将SYS_GUID和序列作为主关键字 How can I make Yahoo! Mail my default email application? Quick .Net File Download Security 如何让win XP实现自动登陆 关于yahoo邮箱如何开通POP access服务 Installing the FrontPage Hit Counter Web Bot ORACLE的启动和关闭 Install Tomcat As windows service 用vb6读写INI文件的模块 Twip&px 我的pg上的上,sql-server-style的new_uuid 可能你没有注意的Exception的属性 答谢cnblogs.com:散两个gmail邀请
用c#获取本机mac(通过dll调用)
35号房客 · 2004-09-28 · via 博客园 - 35号房客

using System;
using System.Net;
using System.Runtime.InteropServices;

public enum NCBCONST 

    NCBNAMSZ   
=16,      /* absolute length of a net name         */ 
    MAX_LANA   
=254,      /* lana's in range 0 to MAX_LANA inclusive   */ 
    NCBENUM      
=0x37,      /* NCB ENUMERATE LANA NUMBERS            */ 
    NRC_GOODRET   
=0x00,      /* good return                              */ 
    NCBRESET    
=0x32,      /* NCB RESET                        */ 
    NCBASTAT    
=0x33,      /* NCB ADAPTER STATUS                  */ 
    NUM_NAMEBUF 
=30,      /* Number of NAME's BUFFER               */ 
}
 

[StructLayout(LayoutKind.Sequential)] 
public struct ADAPTER_STATUS 

    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=6)] 
    
public byte[] adapter_address; 
    
public byte   rev_major;  
    
public byte   reserved0;  
    
public byte   adapter_type;  
    
public byte   rev_minor;  
    
public ushort    duration;  
    
public ushort    frmr_recv;  
    
public ushort    frmr_xmit;  
    
public ushort    iframe_recv_err;  
    
public ushort    xmit_aborts;  
    
public uint   xmit_success;  
    
public uint   recv_success;  
    
public ushort    iframe_xmit_err;  
    
public ushort    recv_buff_unavail;  
    
public ushort    t1_timeouts;  
    
public ushort    ti_timeouts;  
    
public uint   reserved1;  
    
public ushort    free_ncbs;  
    
public ushort    max_cfg_ncbs;  
    
public ushort    max_ncbs;  
    
public ushort    xmit_buf_unavail;  
    
public ushort    max_dgram_size;  
    
public ushort    pending_sess;  
    
public ushort    max_cfg_sess;  
    
public ushort    max_sess;  
    
public ushort    max_sess_pkt_size;  
    
public ushort    name_count; 
}
 

[StructLayout(LayoutKind.Sequential)] 
public struct NAME_BUFFER 
{  
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
    
public byte[] name; 
    
public byte name_num;  
    
public byte name_flags;  
}
 

[StructLayout(LayoutKind.Sequential)] 
public struct NCB 
{  
    
public byte  ncb_command;  
    
public byte  ncb_retcode;  
    
public byte  ncb_lsn;  
    
public byte  ncb_num;  
    
public IntPtr ncb_buffer;  
    
public ushort ncb_length;  
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
    
public byte[]  ncb_callname;  
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NCBNAMSZ)] 
    
public byte[]  ncb_name;  
    
public byte  ncb_rto;  
    
public byte  ncb_sto;  
    
public IntPtr ncb_post;  
    
public byte  ncb_lana_num;  
    
public byte  ncb_cmd_cplt;  
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=10)] 
    
public byte[] ncb_reserve; 
    
public IntPtr ncb_event; 
}
 

[StructLayout(LayoutKind.Sequential)] 
public struct LANA_ENUM 
{  
    
public byte length;  
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.MAX_LANA)] 
    
public byte[] lana; 
}
 

[StructLayout(LayoutKind.Auto)] 
public struct ASTAT 
{  
    
public ADAPTER_STATUS adapt; 
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
=(int)NCBCONST.NUM_NAMEBUF)] 
    
public NAME_BUFFER[] NameBuff; 
}
 
public class Win32API 

    [DllImport(
"NETAPI32.DLL")] 
    
public static extern char Netbios(ref NCB ncb); 
}
 

class GetMac
{
    
public static void Main() 
    

        
string addr=""
        
int cb; 
        ASTAT adapter; 
        NCB Ncb
=new NCB(); 
        
char uRetCode; 
        LANA_ENUM lenum; 

        Ncb.ncb_command 
= (byte)NCBCONST.NCBENUM; 
        cb 
= Marshal.SizeOf(typeof(LANA_ENUM)); 
        Ncb.ncb_buffer 
= Marshal.AllocHGlobal(cb); 
        Ncb.ncb_length 
= (ushort)cb; 
        uRetCode 
= Win32API.Netbios(ref Ncb); 
        lenum 
= (LANA_ENUM)Marshal.PtrToStructure(Ncb.ncb_buffer, typeof(LANA_ENUM)); 
        Marshal.FreeHGlobal(Ncb.ncb_buffer); 
        
if(uRetCode != (short)NCBCONST.NRC_GOODRET) 
            Console.WriteLine(
""); 

        
for(int i=0; i < lenum.length ;i++
        

            Ncb.ncb_command 
= (byte)NCBCONST.NCBRESET; 
            Ncb.ncb_lana_num 
= lenum.lana[i]; 
            uRetCode 
= Win32API.Netbios(ref Ncb); 
            
if(uRetCode != (short)NCBCONST.NRC_GOODRET) 
                Console.WriteLine( 
""); 

            Ncb.ncb_command 
= (byte)NCBCONST.NCBASTAT; 
            Ncb.ncb_lana_num 
= lenum.lana[i]; 
            Ncb.ncb_callname[
0]=(byte)'*'
            cb 
= Marshal.SizeOf(typeof(ADAPTER_STATUS)) + Marshal.SizeOf(typeof(NAME_BUFFER))*(int)NCBCONST.NUM_NAMEBUF; 
            Ncb.ncb_buffer 
= Marshal.AllocHGlobal(cb); 
            Ncb.ncb_length 
= (ushort)cb; 
            uRetCode 
= Win32API.Netbios(ref Ncb); 
            adapter.adapt 
= (ADAPTER_STATUS)Marshal.PtrToStructure(Ncb.ncb_buffer, typeof(ADAPTER_STATUS)); 
            Marshal.FreeHGlobal(Ncb.ncb_buffer); 

            
if (uRetCode == (short)NCBCONST.NRC_GOODRET) 
            

                
if(i>0
                    addr 
+= ":"
                addr 
= string.Format("{0,2:X}{1,2:X}{2,2:X}{3,2:X}{4,2:X}{5,2:X}"
                    adapter.adapt.adapter_address[
0], 
                    adapter.adapt.adapter_address[
1], 
                    adapter.adapt.adapter_address[
2], 
                    adapter.adapt.adapter_address[
3], 
                    adapter.adapt.adapter_address[
4], 
                    adapter.adapt.adapter_address[
5]); 
            }
 
        }
 
        Console.WriteLine( addr.Replace(
' ''0')); 
    }
 
}