Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
В общем случае надо указать полный путь до tclshМожно, например, воспользоваться
env, правда, не знаю, есть ли там подводные камни.#! /usr/bin/env tclsh#!/bin/sh
# DO NOT REMOVE THIS BACKSLASH -> \
exec tclsh "$0" ${1+"$@"}
proc ip2int ip {
set res 0
foreach i [split $ip .] {set res [expr {wide($res<<8 | $i)}]}
set res
}
proc testip {ip} {
set tmp [split $ip .]
if {[llength $tmp] != 4} then {
return 0
}
set index 0
foreach i $tmp {
if {(([regexp \[^0-9\] $i]) || ([string length $i] > 3) || \
(($index == 3) && (($i > 254) || ($i < 1))) || \
(($index <= 2) && (($i > 255) || ($i < 0))))} then {
return 0
}
incr index
}
return 1
}
The address supplied in cp can have one of the following forms:
- a.b.c.d Each of the four numeric parts specifies a byte of the address; the bytes are assigned in left-to-right order to produce the binary address.
- a.b.c Parts a and b specify the first two bytes of the binary address. Part c is interpreted as a 16-bit value that defines the rightmost two bytes of the binary address. This notation is suitable for specifying (outmoded) Class B network addresses.
- 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.
- a The value a is interpreted as a 32-bit value that is stored directly into the binary address without any byte rearrangement.
In all of the above forms, components of the dotted address can be specified in decimal, octal (with a leading 0), or hexadecimal, with a leading 0X). Addresses in any of these forms are collectively termed IPV4 numbers-and-dots notation. The form that uses exactly four decimal numbers is referred to as IPv4 dotted-decimal notation (or sometimes: IPv4 dotted-quad notation).
ping 42 было распространённым явлением. Т.е. потом в эту схему не ломая обратной совместимости затолкали классовую адресацию и всё такое.
Генерация списка IPv4 адресов на TCL и немного систем счисления