schangxiang@126.com
2025-09-17 ab9d9126ced7d6dac0e14c3ede5a49fdb7fc94df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using iWareCommon.Utils;
using iWarePod.Cache.Entity;
using iWarePod.Properties;
using System;
using System.Runtime.InteropServices;
using System.Text;
 
namespace iWarePod.Utils
{
    public class IpHelper
    {
        [DllImport("Iphlpapi.dll")]
 
        static extern int SendARP(Int32 DestIP, Int32 SrcIP, ref Int64 MacAddr, ref Int32 PhyAddrLen);
        [DllImport("Ws2_32.dll")]
 
        static extern Int32 inet_addr(string ipaddr);
        ///<summary>
        /// SendArp获取MAC地址
        ///</summary>
        ///<param name="RemoteIP">目标机器的IP地址如(192.168.1.1)
        ///<returns>目标机器的mac 地址</returns>
        public static string GetMacAddress(string remoteIP)
        {
            try
            {
                var mapIp = CacheEntity.ControlCenterWcfServiceClient.GetIp(remoteIP);
                LogTextHelper.WriteLine(Resources.LogDir, "remoteIP = {0}, mapIp = {1}", remoteIP, mapIp);  
                return mapIp;
            }
            catch(Exception ex)
            {
                LogTextHelper.WriteLog(Resources.LogDir, "IpHelper", "GetMacAddress", ex.Message);  
                return remoteIP;
            }
        }
    }
}