tty scanner
authorTomas Mudrunka <tomas@mudrunka.cz>
Wed, 7 Oct 2015 01:08:40 +0000 (03:08 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Wed, 7 Oct 2015 01:08:40 +0000 (03:08 +0200)
bash/scan_tty.sh [new file with mode: 0755]

diff --git a/bash/scan_tty.sh b/bash/scan_tty.sh
new file mode 100755 (executable)
index 0000000..89878a5
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+scan_tty() {
+       port="$1"
+       rate="$2"
+       timeout 1 cat < "$port" >/dev/null;
+       stty -F "$port" "$rate" cs8 cread clocal
+       timeout 1 cat < "$port" >/dev/null;
+       (
+               banner="$(timeout 7 cat < "$port" | tr '\r\n[:cntrl:]' '...' | grep -i '[a-z0-9]' )"
+               [ -n "$banner" ] && echo -e "$port $rate:\t$banner"
+               #echo "$port:$rate:$banner"
+       ) &
+       stty -F "$port" "$rate" cs8 cread clocal
+       sleep 1
+       #Windows newlines are fore HP ProCurve Switches...
+       #echo -ne '\x03\r\n\x04\x03\r\n\r\n\r\n' > "$port"
+       echo -ne '\x03\r\n\x04\x03' > "$port"
+       sleep 3
+       echo -ne '\r\n\r\n\r\n' > "$port"
+       wait
+}
+
+printf '\033[?7l'
+for port in /dev/ttyUSB*; do
+       for rate in 115200 38400; do
+               #echo -ne "\r$port:$rate:     "
+               banner="$(scan_tty "$port" "$rate")";
+               [ -n "$banner" ] && echo "$banner";
+               echo "$banner" | egrep -i 'linux|root|login|password|user|connect|invalid' >/dev/null && break;
+       done &
+done;
+wait
+printf '\033[?7h'
This page took 0.209273 seconds and 4 git commands to generate.