Durante este fin de semana tengo previsto cambiar de hosting (de Dreamhost a Silicontower) y de versión de WordPress, así que es posible que ocurran cosas extrañas durante un par de días.
Que la fuerza me acompañe.
Durante este fin de semana tengo previsto cambiar de hosting (de Dreamhost a Silicontower) y de versión de WordPress, así que es posible que ocurran cosas extrañas durante un par de días.
Que la fuerza me acompañe.
After dealing with several options, most of them involving a call to a command line tool and parsing the output, which is not really elegant. Other solutions were based on obsolete VBScript client code and ActiveX, even worse.
Finally I found in the excellent pinvoke.net site a very nice and simple example using a simple call to iphlpapi.dll’s SendARP method. The trick was to use ARP to get the MAC from the IP.
Note that this has it’s limitations, as I will only work if the remote machine is in the same network and the packet does not need to go through a router. I was enough for our needs.
Here’s the code I adapted from the example:
public static string GetMAC(IPAddress ipAddr)
{
var mac = new byte[6];
var len = (uint)mac.Length;
var result = SendARP((int)ipAddr.Address, 0, mac, ref len);
if (result != 0)
{
return "MAC not found!";
}
var str = new string[(int)len];
for (var i = 0; i < len; i++)
{
str[i] = mac[i].ToString("x2");
}
return string.Join(":", str);
}
[DllImport("iphlpapi.dll", ExactSpelling = true)]
private static extern int SendARP(int destIP, int srcIP, byte[] pMacAddr, ref uint phyAddrLen);
Enjoy!
Since I acquired a NHibernateProfiler license, an initialization warning message draw my attention, the text seemed quite easy to solve:
WARN: custom type is not Serializable: MyLibrary.MyCustomDataType
[Serializable] attribute to the custom type, but that didn’t make the trick. As it was only a warning, I did not investigate further at that moment.TypeFactory.InjectParameters(userType, parameters);
if (!userType.ReturnedClass.IsSerializable)
{
LogManager.GetLogger(typeof(CustomType)).Warn("custom type is not Serializable: " + userTypeClass);
}
[Serializable] to the class returned by my custom UserType instead than the type itself.