Most active commenters
  • aexaey(3)

←back to thread

1895 points _l4jh | 31 comments | | HN request time: 0.941s | source | bottom
1. DyslexicAtheist ◴[] No.16728255[source]
TIL you can also use 1.1 and it will expand to 1.0.0.1

  $> ping 1.1

  PING 1.1 (1.0.0.1) 56(84) bytes of data.
  64 bytes from 1.0.0.1: icmp_seq=1 ttl=55 time=28.3 ms
  64 bytes from 1.0.0.1: icmp_seq=2 ttl=55 time=33.0 ms
  64 bytes from 1.0.0.1: icmp_seq=3 ttl=55 time=43.6 ms
  64 bytes from 1.0.0.1: icmp_seq=4 ttl=55 time=41.7 ms
  64 bytes from 1.0.0.1: icmp_seq=5 ttl=55 time=56.5 ms
  64 bytes from 1.0.0.1: icmp_seq=6 ttl=55 time=38.4 ms
  64 bytes from 1.0.0.1: icmp_seq=7 ttl=55 time=34.8 ms
  64 bytes from 1.0.0.1: icmp_seq=8 ttl=55 time=45.7 ms
  64 bytes from 1.0.0.1: icmp_seq=9 ttl=55 time=45.2 ms
  64 bytes from 1.0.0.1: icmp_seq=10 ttl=55 time=43.1 ms
replies(5): >>16728294 #>>16728342 #>>16728382 #>>16728420 #>>16729271 #
2. tux3 ◴[] No.16728294[source]
You can also use the decimal value of the IP, without the dots: https://16843009
replies(2): >>16728349 #>>16728998 #
3. aexaey ◴[] No.16728342[source]

  1.2 -> 1.0.0.2
  1.2.3 -> 1.2.0.3
But then, much of software would fail here - Firefox/Chrome for example would both threat that as bareword and redirect to search page.
replies(1): >>16728507 #
4. chisleu ◴[] No.16728349[source]
You can also sing that number to the tune of the famous 8675309 song with very little robato.
replies(2): >>16731230 #>>16734265 #
5. dieulot ◴[] No.16728382[source]
The most useful case for this shortcut is 127.1 -> 127.0.0.1
replies(3): >>16728626 #>>16728629 #>>16729229 #
6. xtreak29 ◴[] No.16728420[source]
Interesting question related to this : https://superuser.com/questions/486788/why-does-pinging-192-...
7. oneweekwonder ◴[] No.16728507[source]
It work as expected if you give it the http://1.2.3 schema prefix.

The input bar is a search bar in modern browsers.

replies(1): >>16728617 #
8. exikyut ◴[] No.16728617{3}[source]
Or if you follow it with a trailing slash, for less typing

  1.1/
replies(1): >>16737431 #
9. avip ◴[] No.16728626[source]
Don't try that in the wild, most sw out there would ignore spec and use some arbitrary regex to validate IP format.

i.e python:

    octets = ip_str.split('.')
    if len(octets) != 4:
        raise AddressValueError("Expected 4 octets in %r" % ip_str)
replies(1): >>16729004 #
10. fwgwgwgch ◴[] No.16728629[source]
Where have you been all my life?
replies(1): >>16728777 #
11. mathgeek ◴[] No.16728777{3}[source]
Sitting at 127.1, apparently.
12. discreditable ◴[] No.16728998[source]
Hex works too: https://0x1010101
replies(2): >>16729117 #>>16729533 #
13. sigjuice ◴[] No.16729004{3}[source]
What spec says that 127.1 and 127.0.0.1 are equivalent?
replies(2): >>16729069 #>>16729584 #
14. nerdwaller ◴[] No.16729069{4}[source]
I don’t actually think it’s in a spec formally but is in a common c lib[0].

> a.b

> Part a specifies the first byte of the binary address. Part b is interpreted as a 24-bit value that defines the rightmost three bytes of the binary address. This notation is suitable for specifying (outmoded) Class C network addresses.

[0]: https://linux.die.net/man/3/inet_aton

replies(2): >>16729230 #>>16730361 #
15. notamy ◴[] No.16729117{3}[source]
Sadly, binary / octal don't work: https://0b1000000010000000100000001 / https://0o100200401
replies(1): >>16729148 #
16. jhanschoo ◴[] No.16729148{4}[source]
Octal works, with the older 0-prefix convention: https://0100200401
replies(1): >>16740445 #
17. aexaey ◴[] No.16729229[source]
0, which is a shorthand for 0.0.0.0 is likely the most code-golf-y way to write localhost, as many [EDIT: Linux] systems alias 0.0.0.0 to 127.0.0.1:

  $ ping 0
  PING 0 (127.0.0.1) 56(84) bytes of data.
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.032 ms
Of course, don't expect this to work universally. A lot of software will try to be clever with input validation, and fail.

Tangentially related: https://fosdem.org/2018/schedule/event/email_address_quiz/

replies(3): >>16729337 #>>16729709 #>>16730226 #
18. sigjuice ◴[] No.16729230{5}[source]
Thanks. I just came across the man page myself while I was writing this tiny program.

  $ cat 127.1.c
  #include <stdio.h>
  #include <arpa/inet.h>
   
  int main(int argc, char *argv[])
  {
      struct in_addr addr;
   
      if (inet_aton(argv[1], &addr))
          printf("%08x\n", addr.s_addr);
   
      return 0;
  }
  $ make 127.1 CFLAGS=-Wall
  cc -Wall     127.1.c   -o 127.1
  $ ./127.1 1.1
  01000001
  $ ./127.1 127.1
  0100007f
19. ◴[] No.16729271[source]
20. mrkstu ◴[] No.16729337{3}[source]
Stays unaliased on macOS:

My-MacBook-Pro:bottle mrkstu$ ping 0 PING 0 (0.0.0.0): 56 data bytes ping: sendto: No route to host

replies(1): >>16731447 #
21. ◴[] No.16729533{3}[source]
22. avip ◴[] No.16729584{4}[source]
You are right, I faithfully assumed it's a spec without checking. Thanks.
23. hartator ◴[] No.16729709{3}[source]
It's not fully true that 127.0.0.1 is the same as 0.0.0.0. For example, binding a webserver to 0.0.0.0 make it on the public network while 127.0.0.1 is strictly localhost.
24. pishpash ◴[] No.16730226{3}[source]
0.0.0.0 is not localhost. It's "any address".
replies(1): >>16730482 #
25. tzs ◴[] No.16730361{5}[source]
The POSIX spec (IEEE 1003.1) says the same thing for inet_addr(), so it does occur in an actual spec.
26. aexaey ◴[] No.16730482{4}[source]
Yes, you're right.

What I was trying to say is - On Linux, INADDR_ANY (0.0.0.0) supplied to connect() or sendto() calls is treated as a synonym for INADDR_LOOPBACK (127.0.0.1) address.

Not so for bind() or course.

27. chisleu ◴[] No.16731230{3}[source]
If you want to memorize the integer, it's not a bad mechanic to use... Why do you hate me?
28. jamiek88 ◴[] No.16731447{4}[source]
However ping to 127.1 works the same as localhost.
29. finnh ◴[] No.16734265{3}[source]
I just upvoted you, bc (a) funny and (b) TIL a new word (rubato).
30. WorldMaker ◴[] No.16737431{4}[source]
Or if you prefix it with //

  //1.1.1.1
It's one more letter than a suffix, but as a prefix its a bit clearer. I've known companies to post LAN hostname addresses that way, and in written/printed materials it stands out pretty clearly as an address to type.

It follows the URL standards (no schema implies current or default schema). Many auto-linking tools (such as a Markdown, Word) recognize it by default (though sometimes results are unpredictable given schema assumptions). It's also increasingly the recommendation for HTML resources where you do want to help insure same-schema requests (good example cross-server/CDN CSS and JS links now are typically written as //css-host.example.com/some/css/file.css).

31. notamy ◴[] No.16740445{5}[source]
Ah, I had completely forgotten about that. Thanks!