Author

Topic: Hex value of ip address why reversed? (Read 219 times)

jr. member
Activity: 413
Merit: 5
March 11, 2018, 08:56:56 PM
#7
If my real IP address is 175.126.37.238 and this address should be input above, then 0xee257eaf   is correct? Internet site hex to ip
https://www.browserling.com/tools/hex-to-ip
shows this 0xee257eaf  is 238.37.126.175


This is due to Endianness (https://en.wikipedia.org/wiki/Endianness).

When communicating via a network, you don't know how your counterparty is 'reading' the values.
Most significant bit at the most left or most right position?

Big-endian (most significant byte has the lowest address [left-to-right reading]) is also referred to network byte order.
Depending on the system you are using your pc might use big- or low- endian format. But when communicating via network, always big endian is used (IPv4/6, TCP/UDP).

Thats the reason for the mysterious reverse order.



I don't know Endian well, but perfect description.
legendary
Activity: 1624
Merit: 2481
March 11, 2018, 04:32:32 AM
#6
If my real IP address is 175.126.37.238 and this address should be input above, then 0xee257eaf   is correct? Internet site hex to ip
https://www.browserling.com/tools/hex-to-ip
shows this 0xee257eaf  is 238.37.126.175


This is due to Endianness (https://en.wikipedia.org/wiki/Endianness).

When communicating via a network, you don't know how your counterparty is 'reading' the values.
Most significant bit at the most left or most right position?

Big-endian (most significant byte has the lowest address [left-to-right reading]) is also referred to network byte order.
Depending on the system you are using your pc might use big- or low- endian format. But when communicating via network, always big endian is used (IPv4/6, TCP/UDP).

Thats the reason for the mysterious reverse order.


jr. member
Activity: 413
Merit: 5
March 11, 2018, 03:03:02 AM
#5
I admit that I'm not exactly sure what your context is or what you're looking at, but over the wire, IP addresses are encoded in big-endian format.  

If that's the kind of 'reversal' you're talking about, then I suggest you take a look at:

Code:
$ man 3 htons

so at net.cpp, unsigned int pnSeed[] = {  0xee257eaf  }

If my real IP address is 175.126.37.238 and this address should be input above, then 0xee257eaf   is correct? Internet site hex to ip
https://www.browserling.com/tools/hex-to-ip
shows this 0xee257eaf  is 238.37.126.175
member
Activity: 210
Merit: 26
High fees = low BTC price
March 10, 2018, 06:47:20 AM
#4
but over the wire, IP addresses are encoded in big-endian format.  

here is the code that works with DNS A-Record lookup for Ipv4
Code:
private static byte[] DnsBytesReverseLookup(string IP)
       {//Builds up a request for a Reverse DNS-Lookup
           byte[] Head = SeedTheHead(DateTime.Now.Minute);
           byte[] Footer = new byte[18] { 7, 105, 110, 45, 97, 100, 100, 114, 4, 97, 114, 112, 97, 0, 0, 12, 0, 1 };//in-addr.arpa
           string[] IPDigits = IP.Split('.');
           MemoryStream MS = new MemoryStream();
           MS.Write(Head, 0, Head.Length);
           byte[] IP0 = ByteString(IPDigits[0]); byte[] IP1 = ByteString(IPDigits[1]); byte[] IP2 = ByteString(IPDigits[2]); byte[] IP3 = ByteString(IPDigits[3]);
           MS.Write(IP3, 0, IP3.Length); MS.Write(IP2, 0, IP2.Length); MS.Write(IP1, 0, IP1.Length); MS.Write(IP0, 0, IP0.Length);
           MS.Write(Footer, 0, Footer.Length);
           return MS.ToArray();
       }

private static byte[] ByteString(string Value)
       {//Used to build up a DNS request
           byte[] B = new byte[Value.Length + 1];
           B[0] = (byte)Value.Length;
           B[1] = (byte)Value[0];
           if (Value.Length > 1)
               B[2] = (byte)Value[1];
           if (Value.Length > 2)
               B[3] = (byte)Value[2];
           return B;
       }

The order is backwards but it's not hex

legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
March 10, 2018, 02:39:30 AM
#3
I admit that I'm not exactly sure what your context is or what you're looking at, but over the wire, IP addresses are encoded in big-endian format.  

If that's the kind of 'reversal' you're talking about, then I suggest you take a look at:

Code:
$ man 3 htons
member
Activity: 210
Merit: 26
High fees = low BTC price
March 09, 2018, 09:07:26 PM
#2
I tested 10.11.12.13 and got 0a.0b.0c.0d so it looks fine to me but why anyone
wants to store ip's hex seems strange to me but often ips are converted to longs so that you
can write code like

if (IP>=12334567 && IP<=89101112)
   do something with range.






jr. member
Activity: 413
Merit: 5
March 09, 2018, 07:57:59 PM
#1
net.cpp's  [ pnSeed ] variable, there are hex value of ip address.

Is it reverse of ip address?

Why its result and this site's result is reverse?

https://www.browserling.com/tools/ip-to-hex
Jump to: