请问以下该段程序应该写在什么里面.是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;
}
完整的程序应该怎么写呢? 我用的是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;
}
解决方案 »
- mschart 横坐标显示时间为年月日时分秒的问题
- 大家一定要来玩一下 可能还能在本帖游戏中学到知识
- 关于axWindowsMediaPlayer1使用的问题
- c# 初学者问 界面设计: 谁能设计这样的界面?告诉我用那个控件
- 怎样在.net2003实现如ctrl+c的快捷键啊?
- 去年用了一个第三方的数据显示控件,今年在打开修改时遇到一个奇怪的错误
- 问题问题:C#如何获取屏幕分辨率??????急!!谢谢!!
- 急急急!!!!!......菜鸟100分 求教 WinForm 应用程序通过HTTP代理及用户验证 调用 Internet WebServices 源代码!!(分不够可再加)
- ReportView 隐藏某一项的问题
- 抵制日货大散分(2)
- C#上传GIF动画的问题
- 连接sql server 时,出现问题,帮解决阿?
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();
}
}
}
http://blog.csdn.net/chengking/archive/2005/10/07/496627.aspx
这种方法不行,我已经试过了,编译后有N多的错误!!!
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;
}
}
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;
}
}
程序可以运行成功,可运行时只有一个DOS窗口一闪而过!
我怎样才能得到返回值呢?
返回值应该是网关MAC地址!!!
的返回值不就是MAC地址吗?