I have put lot of efforts, googled and tried all possible ways. But I did not got satisfaction so I come here finally.
I want to convert below line of code [C#] into java.
1] Method used to convert IP into uint
private uint GetIP(string strIp)
{
System.Net.IPAddress ipaddress = System.Net.IPAddress.Parse(strIp);
uint lIp = (uint)ipaddress.Address;
lIp = ((lIp & 0xFF000000) >> 24) + ((lIp & 0x00FF0000) >> 8) + ((lIp & 0x0000FF00) << 8) + ((lIp & 0x000000FF) << 24);
MessageBox.Show(strIp + " = " + lIp);
return (lIp);
}
2] Method used to convert String into IntPtr
IntPtr iPtr = Marshal.StringToHGlobalAnsi("Hello");
Please help me as soon as possible. Thanks in advance.
I really appreciate help.
What I have tried:
I have tried following code for converting IP to Long, not sure is it right or wrong .
public static long ipToLong(String ipAddress) {
String[] ipAddressInArray = ipAddress.split("\\.");
long result = 0;
for (int i = 0; i < ipAddressInArray.length; i++) {
int power = 3 - i;
int ip = Integer.parseInt(ipAddressInArray[i]);
result += ip * Math.pow(256, power);
}
return result;
}
For String to IntPtr, tried to convert String to Ascii and then tried to use Intger by reference.