Reputation: 97
Is there any way to convert an IP address string to a hex string, (including dots), and then return the converted hex value!
"10.10.10.11"
to hex(7):31,00,30,00,2e,00,31,00,30,00,2e,00,31,00,30,00,2e,00,31,00,00,00,00,00
Cheers!
Upvotes: 0
Views: 1905
Reputation: 8694
Reading your question, I understand that you actually want to convert the IP address string to its unicode representation, from which you then want to generate a comma separated list of the underlying bytes (encoded in hex).
This will do the trick:
string.Join(",", Encoding.Unicode.GetBytes("10.10.10.11").Select(x => x.ToString("X2")))
Output:
31,00,30,00,2E,00,31,00,30,00,2E,00,31,00,30,00,2E,00,31,00,31,00
Upvotes: 2
Reputation: 191027
Use the System.Net.IPAddress
class, then you should be able to get it as an array of bytes.
var address = System.Net.IPAddress.Parse("10.10.10.11");
var bytes = address.GetAddressBytes();
Upvotes: 1