Bitcoin Forum
May 11, 2024, 07:46:00 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Hex value of ip address why reversed?  (Read 195 times)
wsxdrfv (OP)
Jr. Member
*
Offline Offline

Activity: 405
Merit: 5


View Profile WWW
March 10, 2018, 12:57:59 AM
 #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
1715456760
Hero Member
*
Offline Offline

Posts: 1715456760

View Profile Personal Message (Offline)

Ignore
1715456760
Reply with quote  #2

1715456760
Report to moderator
"In a nutshell, the network works like a distributed timestamp server, stamping the first transaction to spend a coin. It takes advantage of the nature of information being easy to spread but hard to stifle." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715456760
Hero Member
*
Offline Offline

Posts: 1715456760

View Profile Personal Message (Offline)

Ignore
1715456760
Reply with quote  #2

1715456760
Report to moderator
1715456760
Hero Member
*
Offline Offline

Posts: 1715456760

View Profile Personal Message (Offline)

Ignore
1715456760
Reply with quote  #2

1715456760
Report to moderator
Anti-Cen
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 10, 2018, 02:07:26 AM
 #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.







Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
tspacepilot
Legendary
*
Offline Offline

Activity: 1456
Merit: 1078


I may write code in exchange for bitcoins.


View Profile
March 10, 2018, 07:39:30 AM
Merited by mattcode (1)
 #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
Anti-Cen
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 10, 2018, 11: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


Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
wsxdrfv (OP)
Jr. Member
*
Offline Offline

Activity: 405
Merit: 5


View Profile WWW
March 11, 2018, 07: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
bob123
Legendary
*
Offline Offline

Activity: 1624
Merit: 2481



View Profile WWW
March 11, 2018, 09:32:32 AM
Merited by achow101 (2), ABCbits (2)
 #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.



wsxdrfv (OP)
Jr. Member
*
Offline Offline

Activity: 405
Merit: 5


View Profile WWW
March 12, 2018, 01:56:56 AM
 #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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!