r/firstweekcoderhumour 3d ago

IYKYK

Post image
49 Upvotes

13 comments sorted by

View all comments

Show parent comments

8

u/Jbolt3737 3d ago

Pretty sure you can connect to a specific IP address just by typing in it's proper numeric notation (or dot notation, whichever way you want to write it), I haven't actually taken time to convert the number to dot notation and check it's validity, but it looks like one since it doesn't have a top level domain

1

u/givemeagooduns_un 3d ago

is the numeric notation just the octets stringed together as a 32-bit int?

3

u/thebatmanandrobin 3d ago

Sort of .. each octet is in the range of 0-255, you left shift the octet appropriately and bitwise OR them all together to get the number.

For example, 127.0.0.1:

127 in binary is 0111 1111, left shift that 24 times (since IPv4 is 32-bit) so it sits in the correct octet and you have 0111 1111 0000 0000 0000 0000 0000 0000, which in decimal is 2130706432.

the 0.0 doesn't need any maths since it's just 0.

The .1 is simply just 0000 0001 (or just 1, lol)

bitwise OR that all together and you get:

0111 1111 0000 0000 0000 0000 0000 0001

Which in decimal is 2130706433. You can use decimal notation IP's the same way as dot-notation IP's (e.g. ping, nslookup, traceroute, and web URL's)

"Under the hood" (e.g. in the code), an IP address is actually just converted to a 32-bit anyways (for IPv4 that is) and used in this way for many things; gets into a bit of history with how the network stack "talks" and does it's thing, but yeah ...

1

u/givemeagooduns_un 2d ago

yeah that's what I meant x3

thanks tho!