i.e python:
octets = ip_str.split('.')
if len(octets) != 4:
raise AddressValueError("Expected 4 octets in %r" % ip_str)> 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.
$ 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 $ 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/