请问以下该段程序应该写在什么里面.是CLASS吗?应该怎么生成运行该程序呢????
完整的程序应该怎么写呢?    我用的是VS 2005[DllImport("Iphlpapi.dll")] 
private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); 
[DllImport("Ws2_32.dll")] 
private static extern Int32 inet_addr(string ip); /// 
/// 根据ip得到网卡mac地址 
/// 
/// 给出的ip地址 
/// 对应ip的网卡mac地址 
public static Int64 GetMACByIP(string ip) 

Int32 ldest= inet_addr(ip); //目的地的ip 
try 

Int64 macinfo = new Int64(); 
Int32 len = 6; 
int res = SendARP(ldest,0, ref macinfo, ref len); 
return macinfo; 

catch(Exception err) 

Console.WriteLine("Error:{0}",err.Message); 

return 0; 
}

解决方案 »

  1.   

    建立一个Console Application,代码如下using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport("Iphlpapi.dll")]
            private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
            [DllImport("Ws2_32.dll")]
            private static extern Int32 inet_addr(string ip);        ///
            /// 根据ip得到网卡mac地址
            ///
            /// 给出的ip地址
            /// 对应ip的网卡mac地址
            public static Int64 GetMACByIP(string ip)
            {
                Int32 ldest = inet_addr(ip); //目的地的ip
                try
                {
                    Int64 macinfo = new Int64();
                    Int32 len = 6;
                    int res = SendARP(ldest, 0, ref macinfo, ref len);
                    return macinfo;
                }
                catch (Exception err)
                {
                    Console.WriteLine("Error:{0}", err.Message);
                }
                return 0;
            }
            static void Main(string[] args)
            {
                Console.WriteLine("Please input IP");
                string userinput = Console.ReadLine();
                int64 mac = GetMACByIP(userinput);
                Console.WriteLine(String.Format("MAC:{0}", mac));
                Console.ReadLine();
            }
        }    
    }
      

  2.   

    看一下调用API示例:
    http://blog.csdn.net/chengking/archive/2005/10/07/496627.aspx
      

  3.   

    TO:icehawk(流浪他乡) 
    这种方法不行,我已经试过了,编译后有N多的错误!!!
      

  4.   

    可以放一个class里
    public MyClass
    {
    [DllImport("Iphlpapi.dll")] 
    private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); 
    [DllImport("Ws2_32.dll")] 
    private static extern Int32 inet_addr(string ip); /// 
    /// 根据ip得到网卡mac地址 
    /// 
    /// 给出的ip地址 
    /// 对应ip的网卡mac地址 
    public static Int64 GetMACByIP(string ip) 

    Int32 ldest= inet_addr(ip); //目的地的ip 
    try 

    Int64 macinfo = new Int64(); 
    Int32 len = 6; 
    int res = SendARP(ldest,0, ref macinfo, ref len); 
    return macinfo; 

    catch(Exception err) 

    Console.WriteLine("Error:{0}",err.Message); 

    return 0; 
    }
    }
      

  5.   

    上面的错了
    public class MyClass
    {
      [DllImport("Iphlpapi.dll")] 
    private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); 
    [DllImport("Ws2_32.dll")] 
    private static extern Int32 inet_addr(string ip); /// 
    /// 根据ip得到网卡mac地址 
    /// 
    /// 给出的ip地址 
    /// 对应ip的网卡mac地址 
    public static Int64 GetMACByIP(string ip) 

    Int32 ldest= inet_addr(ip); //目的地的ip 
    try 

    Int64 macinfo = new Int64(); 
    Int32 len = 6; 
    int res = SendARP(ldest,0, ref macinfo, ref len); 
    return macinfo; 

    catch(Exception err) 

    Console.WriteLine("Error:{0}",err.Message); 

    return 0; 
    }
    }
      

  6.   

    TO:jimgreat() 
    程序可以运行成功,可运行时只有一个DOS窗口一闪而过!
    我怎样才能得到返回值呢?
    返回值应该是网关MAC地址!!!
      

  7.   

    public static Int64 GetMACByIP(string ip) 
    的返回值不就是MAC地址吗?