| 1 |
#!/usr/bin/expect -f |
| 2 |
# |
| 3 |
# Usage: testing.exp <path to arping> <ifname> <ip address> <mac address> |
| 4 |
# |
| 5 |
# Test all cases against a "normal" machine: |
| 6 |
# * Responds to ARP |
| 7 |
# * Responds to ping |
| 8 |
# * Doesn't respond to broadcast pings. |
| 9 |
# |
| 10 |
# Abnormal machines, to be tested elsewhere: |
| 11 |
# * Proxy ARP |
| 12 |
# * Respond to broadcast pings |
| 13 |
# * Lost packets |
| 14 |
# * Duplicated replies |
| 15 |
# |
| 16 |
# Tested here: |
| 17 |
# * -a |
| 18 |
# * -c |
| 19 |
# * -d (minimally) |
| 20 |
# * -D |
| 21 |
# * -e |
| 22 |
# * -h |
| 23 |
# * -q (soon) |
| 24 |
# * -r |
| 25 |
# * -R |
| 26 |
# * -s (soon) |
| 27 |
# * -S (soon) |
| 28 |
# * -t |
| 29 |
# * -T |
| 30 |
# * -u (soon) |
| 31 |
# * -v (soon) |
| 32 |
# * -w (soon) |
| 33 |
# * -W (soon) |
| 34 |
# |
| 35 |
# Not tested here: |
| 36 |
# * -0 |
| 37 |
# * -A (forced on with mac ping) |
| 38 |
# * -b |
| 39 |
# * -B |
| 40 |
# * -p |
| 41 |
# * -P |
| 42 |
# * -U |
| 43 |
# * -V |
| 44 |
# * Mac ping without -T. |
| 45 |
# |
| 46 |
set bin [lindex $argv 0] |
| 47 |
set ifname [lindex $argv 1] |
| 48 |
set ip [lindex $argv 2] |
| 49 |
set mac [lindex $argv 3] |
| 50 |
set bad_ip "1.2.4.3" |
| 51 |
set bad_mac "00:11:22:33:44:55" |
| 52 |
|
| 53 |
# Check if "stty -oxtabs" is a thing. |
| 54 |
# It is on OpenBSD, but not Linux. |
| 55 |
spawn tty |
| 56 |
expect eof |
| 57 |
spawn "stty" "-oxtabs" |
| 58 |
catch wait result |
| 59 |
if {[lindex $result 3] == 0} { |
| 60 |
set stty_init "-oxtabs" |
| 61 |
} |
| 62 |
|
| 63 |
# Helper functions. |
| 64 |
proc want_err {code} { |
| 65 |
lassign [wait] pid spawnid os_error_flag value |
| 66 |
if {$os_error_flag != 0} { |
| 67 |
puts "No error code provided" |
| 68 |
exit 1 |
| 69 |
} |
| 70 |
if {$value != $code} { |
| 71 |
puts "Wrong error code. Want $code, got $value" |
| 72 |
exit 1 |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
send_user -- "--------------- No options ------------------\n" |
| 78 |
spawn $bin |
| 79 |
expect -re "ARPing 2\.\d+, by Thomas Habets <[email protected]>\r |
| 80 |
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r |
| 81 |
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r |
| 82 |
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r |
| 83 |
For complete usage info, use --help or check the manpage.\r |
| 84 |
" |
| 85 |
expect eof |
| 86 |
want_err 1 |
| 87 |
|
| 88 |
send_user -- "--------------- -h ------------------\n" |
| 89 |
spawn $bin -h |
| 90 |
expect -re "ARPing 2\.\d+, by Thomas Habets <[email protected]>\r |
| 91 |
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r |
| 92 |
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r |
| 93 |
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r |
| 94 |
For complete usage info, use --help or check the manpage.\r |
| 95 |
" |
| 96 |
expect eof |
| 97 |
want_err 0 |
| 98 |
|
| 99 |
send_user -- "--------------- --help ------------------\n" |
| 100 |
spawn $bin --help |
| 101 |
expect -re "ARPing 2\.\d+, by Thomas Habets <[email protected]>\r |
| 102 |
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r |
| 103 |
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r |
| 104 |
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r |
| 105 |
\r |
| 106 |
" |
| 107 |
expect "Report bugs to: [email protected]\r |
| 108 |
Arping home page: <http://www.habets.pp.se/synscan/>\r |
| 109 |
Development repo: http://github.com/ThomasHabets/arping\r |
| 110 |
" |
| 111 |
expect eof |
| 112 |
want_err 0 |
| 113 |
|
| 114 |
send_user -- "--------------- Bad interface ------------------\n" |
| 115 |
spawn $bin -i uhtaonuhoes $ip |
| 116 |
expect -re "arping: libnet_init.*\r" |
| 117 |
expect "\r" { |
| 118 |
# Make sure double-endline is stripped. |
| 119 |
exit 1 |
| 120 |
} |
| 121 |
want_err 1 |
| 122 |
|
| 123 |
send_user -- "--------------- Ping IP Simple ------------------\n" |
| 124 |
spawn $bin -c 1 $ip |
| 125 |
expect -re "ARPING $ip\r |
| 126 |
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r |
| 127 |
\r |
| 128 |
--- $ip statistics ---\r |
| 129 |
1 packets transmitted, 1 packets received, 0% unanswered \\(0 extra\\)\r |
| 130 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r |
| 131 |
" |
| 132 |
expect eof |
| 133 |
want_err 0 |
| 134 |
|
| 135 |
send_user -- "--------------- Ping IP Raw (-r) ------------------\n" |
| 136 |
spawn $bin -c 2 -r $ip |
| 137 |
expect -re "$mac\r |
| 138 |
$mac\r |
| 139 |
" |
| 140 |
expect eof |
| 141 |
want_err 0 |
| 142 |
|
| 143 |
send_user -- "--------------- Ping IP Raw audio (-r -a) ------------------\n" |
| 144 |
spawn $bin -c 2 -r -a $ip |
| 145 |
expect -re "\a$mac\r |
| 146 |
\a$mac\r |
| 147 |
" |
| 148 |
expect eof |
| 149 |
want_err 0 |
| 150 |
|
| 151 |
send_user -- "--------------- Ping IP Raw audio bad dest (-r -e) ------------------\n" |
| 152 |
spawn $bin -c 2 -r -i "$ifname" -e $bad_ip |
| 153 |
expect -re "\a\a" |
| 154 |
expect eof |
| 155 |
want_err 1 |
| 156 |
|
| 157 |
send_user -- "--------------- Ping IP reverse raw (-R) ------------------\n" |
| 158 |
spawn $bin -c 2 -R $ip |
| 159 |
expect -re "$ip\r |
| 160 |
$ip\r |
| 161 |
" |
| 162 |
expect eof |
| 163 |
want_err 0 |
| 164 |
|
| 165 |
send_user -- "--------------- Ping IP double raw (-R) ------------------\n" |
| 166 |
spawn $bin -c 2 -R -r $ip |
| 167 |
expect -re "$mac $ip\r |
| 168 |
$mac $ip\r |
| 169 |
" |
| 170 |
expect eof |
| 171 |
want_err 0 |
| 172 |
|
| 173 |
send_user -- "--------------- Ping IP max 2 (-C) ------------------\n" |
| 174 |
spawn $bin -C 2 -c 10 $ip |
| 175 |
expect -re "ARPING $ip\r |
| 176 |
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r |
| 177 |
\(42|60\) bytes from $mac \\($ip\\): index=1 time=(.*)sec\r |
| 178 |
\r |
| 179 |
--- $ip statistics ---\r |
| 180 |
2 packets transmitted, 2 packets received, 0% unanswered \\(0 extra\\)\r |
| 181 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 182 |
" |
| 183 |
expect eof |
| 184 |
want_err 0 |
| 185 |
|
| 186 |
send_user -- "--------------- Ping IP x 3 (-c) ------------------\n" |
| 187 |
spawn $bin -c 3 $ip |
| 188 |
expect -re "ARPING $ip\r |
| 189 |
\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r |
| 190 |
\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r |
| 191 |
\(42|60\) bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\r |
| 192 |
\r |
| 193 |
--- $ip statistics ---\r |
| 194 |
3 packets transmitted, 3 packets received, 0% unanswered \\(0 extra\\)\r |
| 195 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 196 |
" |
| 197 |
expect eof |
| 198 |
want_err 0 |
| 199 |
|
| 200 |
send_user -- "--------------- Ping IP x 3 with audio (-a) ------------------\n" |
| 201 |
spawn $bin -c 3 -a $ip |
| 202 |
expect -re "ARPING $ip\r |
| 203 |
\a\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r |
| 204 |
\a\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r |
| 205 |
\a\(42|60\) bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\r |
| 206 |
\r |
| 207 |
--- $ip statistics ---\r |
| 208 |
3 packets transmitted, 3 packets received, 0% unanswered \\(0 extra\\)\r |
| 209 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 210 |
" |
| 211 |
expect eof |
| 212 |
want_err 0 |
| 213 |
|
| 214 |
send_user -- "--------- Ping IP x 2 with inverted audio (-e) ------------\n" |
| 215 |
spawn $bin -c 2 -e $ip |
| 216 |
expect -re "ARPING $ip\r |
| 217 |
\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r |
| 218 |
\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r |
| 219 |
\r |
| 220 |
--- $ip statistics ---\r |
| 221 |
2 packets transmitted, 2 packets received, 0% unanswered \\(0 extra\\)\r |
| 222 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 223 |
" |
| 224 |
expect eof |
| 225 |
want_err 0 |
| 226 |
|
| 227 |
send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e) ------------\n" |
| 228 |
spawn $bin -c 2 -i "$ifname" -e "$bad_ip" |
| 229 |
expect -re "ARPING $bad_ip\r |
| 230 |
\aTimeout\r |
| 231 |
\aTimeout\r |
| 232 |
\r |
| 233 |
--- $bad_ip statistics ---\r |
| 234 |
2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r |
| 235 |
\r |
| 236 |
" |
| 237 |
expect eof |
| 238 |
want_err 1 |
| 239 |
|
| 240 |
send_user -- "--------- Ping IP x 2 with inverted audio (-e -D) ------------\n" |
| 241 |
spawn $bin -c 2 -e -D $ip |
| 242 |
expect "!!\t 0% packet loss (0 extra)\r\n" |
| 243 |
expect eof |
| 244 |
want_err 0 |
| 245 |
|
| 246 |
send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e -D) ------------\n" |
| 247 |
spawn $bin -c 2 -e -i $ifname -D "$bad_ip" |
| 248 |
expect "\a.\a.\t100% packet loss (0 extra)\r\n" |
| 249 |
expect eof |
| 250 |
want_err 1 |
| 251 |
|
| 252 |
send_user -- "--------------- Ping IP cisco style (-D) ------------------\n" |
| 253 |
spawn $bin -c 3 -D $ip |
| 254 |
expect "!!!\t 0% packet loss (0 extra)\r\n" |
| 255 |
expect eof |
| 256 |
want_err 0 |
| 257 |
|
| 258 |
send_user -- "--------------- Ping IP cisco style with audio (-D -a) -----------\n" |
| 259 |
spawn $bin -c 3 -D -a $ip |
| 260 |
expect "\a!\a!\a!\t 0% packet loss (0 extra)\r\n" |
| 261 |
expect eof |
| 262 |
want_err 0 |
| 263 |
|
| 264 |
send_user -- "--------------- Ping IP Targeted (-t) ------------------\n" |
| 265 |
spawn $bin -c 1 -t $mac $ip |
| 266 |
expect -re "ARPING $ip\r |
| 267 |
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r |
| 268 |
\r |
| 269 |
--- $ip statistics ---\r |
| 270 |
1 packets transmitted, 1 packets received, 0% unanswered \\(0 extra\\)\r |
| 271 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r |
| 272 |
" |
| 273 |
expect eof |
| 274 |
want_err 0 |
| 275 |
|
| 276 |
send_user -- "--------------- Ping IP Mistargeted (-t) ------------------\n" |
| 277 |
spawn $bin -c 1 -t $bad_mac $ip |
| 278 |
expect "ARPING $ip\r |
| 279 |
Timeout\r |
| 280 |
\r |
| 281 |
--- $ip statistics ---\r |
| 282 |
1 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r |
| 283 |
" |
| 284 |
expect eof |
| 285 |
want_err 1 |
| 286 |
|
| 287 |
send_user -- "--------------- Ping MAC with IP destination ------------------\n" |
| 288 |
spawn $bin -A -c 1 -T $ip $mac |
| 289 |
expect -re "ARPING $mac\r |
| 290 |
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r |
| 291 |
\r |
| 292 |
--- $mac statistics ---\r |
| 293 |
1 packets transmitted, 1 packets received, 0% unanswered \\(0 extra\\)\r |
| 294 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r |
| 295 |
" |
| 296 |
expect eof |
| 297 |
want_err 0 |
| 298 |
|
| 299 |
send_user -- "--------------- Ping MAC Raw (-r) ------------------\n" |
| 300 |
spawn $bin -c 2 -r -T $ip $mac |
| 301 |
expect -re "$ip\r |
| 302 |
$ip\r |
| 303 |
" |
| 304 |
expect eof |
| 305 |
want_err 0 |
| 306 |
|
| 307 |
send_user -- "--------------- Ping MAC Raw audio (-r -a) ------------------\n" |
| 308 |
spawn $bin -c 2 -a -r -T $ip $mac |
| 309 |
expect -re "\a$ip\r |
| 310 |
\a$ip\r |
| 311 |
" |
| 312 |
expect eof |
| 313 |
want_err 0 |
| 314 |
|
| 315 |
send_user -- "--------------- Ping MAC Raw audio bad dest (-r -e) ------------------\n" |
| 316 |
spawn $bin -c 2 -r -e -T $ip $bad_mac |
| 317 |
expect -re "\a\a" |
| 318 |
expect eof |
| 319 |
want_err 1 |
| 320 |
|
| 321 |
send_user -- "--------------- Ping MAC reverse raw (-R) ------------------\n" |
| 322 |
spawn $bin -c 2 -R -T $ip $mac |
| 323 |
expect -re "$mac\r |
| 324 |
$mac\r |
| 325 |
" |
| 326 |
expect eof |
| 327 |
want_err 0 |
| 328 |
|
| 329 |
send_user -- "--------------- Ping MAC double raw (-a -R) ------------------\n" |
| 330 |
spawn $bin -c 2 -R -r -T $ip $mac |
| 331 |
expect -re "$mac $ip\r |
| 332 |
$mac $ip\r |
| 333 |
" |
| 334 |
expect eof |
| 335 |
want_err 0 |
| 336 |
|
| 337 |
|
| 338 |
send_user -- "--------------- Ping MAC max 2 (-C) ------------------\n" |
| 339 |
spawn $bin -A -C 2 -c 10 -T $ip $mac |
| 340 |
expect -re "ARPING $mac\r |
| 341 |
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r |
| 342 |
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=1 time=(.*)sec\r |
| 343 |
\r |
| 344 |
--- $mac statistics ---\r |
| 345 |
2 packets transmitted, 2 packets received, 0% unanswered \\(0 extra\\)\r |
| 346 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 347 |
" |
| 348 |
expect eof |
| 349 |
want_err 0 |
| 350 |
|
| 351 |
send_user -- "--------------- Ping MAC cisco style (-D) ------------------\n" |
| 352 |
spawn $bin -A -c 3 -D -T $ip $mac |
| 353 |
expect "!!!\t 0% packet loss (0 extra)\r\n" |
| 354 |
expect eof |
| 355 |
want_err 0 |
| 356 |
|
| 357 |
send_user -- "--------------- Ping MAC cisco style with audio (-D -a) -----------\n" |
| 358 |
spawn $bin -A -c 3 -D -a -T $ip $mac |
| 359 |
expect "\a!\a!\a!\t 0% packet loss (0 extra)\r\n" |
| 360 |
expect eof |
| 361 |
want_err 0 |
| 362 |
|
| 363 |
send_user -- "--------- Ping MAC x 2 with inverted audio (-e) ------------\n" |
| 364 |
spawn $bin -c 2 -T $ip "$mac" |
| 365 |
expect -re "ARPING $mac\r |
| 366 |
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r |
| 367 |
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=1 time=(.*)sec\r |
| 368 |
\r |
| 369 |
--- $mac statistics ---\r |
| 370 |
2 packets transmitted, 2 packets received, 0% unanswered \\(0 extra\\)\r |
| 371 |
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r |
| 372 |
" |
| 373 |
expect eof |
| 374 |
want_err 0 |
| 375 |
|
| 376 |
send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e) ------------\n" |
| 377 |
spawn $bin -e -c 2 -T $ip "$bad_mac" |
| 378 |
expect -re "ARPING $bad_mac\r |
| 379 |
\aTimeout\r |
| 380 |
\aTimeout\r |
| 381 |
\r |
| 382 |
--- $bad_mac statistics ---\r |
| 383 |
2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r |
| 384 |
\r |
| 385 |
" |
| 386 |
expect eof |
| 387 |
want_err 1 |
| 388 |
|
| 389 |
send_user -- "--------- Ping MAC x 2 with inverted audio (-e -D) ------------\n" |
| 390 |
spawn $bin -A -e -c 2 -D -T $ip $mac |
| 391 |
expect "!!\t 0% packet loss (0 extra)\r\n" |
| 392 |
expect eof |
| 393 |
want_err 0 |
| 394 |
|
| 395 |
send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e -D) ------------\n" |
| 396 |
spawn $bin -A -c 2 -e -i $ifname -D -T $ip $bad_mac |
| 397 |
expect "\a.\a.\t100% packet loss (0 extra)\r\n" |
| 398 |
expect eof |
| 399 |
want_err 1 |
| 400 |
|
| 401 |
send_user -- "--------- Detect duplicate ------------\n" |
| 402 |
spawn $bin -c 2 -d $ip |
| 403 |
expect eof |
| 404 |
want_err 0 |
| 405 |
|
| 406 |
send_user -- "--------- Detect duplicate of self ------------\n" |
| 407 |
spawn $bin -c 2 -d |
| 408 |
expect eof |
| 409 |
want_err 0 |
| 410 |
|
| 411 |
send_user -- "--------- Too many args ------------\n" |
| 412 |
spawn $bin -c 2 1.1.1.1 1.1.1.1 |
| 413 |
expect eof |
| 414 |
want_err 1 |
| 415 |
|
| 416 |
send_user -- "---------------------------------------------------------\n" |
| 417 |
send_user -- "All tests passed\n" |