浏览代码

add termux-shortcuts - wrapper to find peer IP when usb tethered

Daniel Sheffield 2 天之前
父节点
当前提交
17ca2e48a4
共有 1 个文件被更改,包括 33 次插入0 次删除
  1. 33 0
      termux-shortcuts/.shortcuts/sweep.sh

+ 33 - 0
termux-shortcuts/.shortcuts/sweep.sh

@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+IFACE=rndis0
+
+getip(){
+    local iface="$1"
+    ifconfig | awk -v FS="\n" -vRS="\n\n" "/$iface/ {print \$0}" | awk '/inet / {print $2}'
+}
+
+MYIP="$(getip "$IFACE")"
+[ "$MYIP" ] || {
+    echo "Failed to find ip on $IFACE" >&2
+    exit 1
+}
+
+# XXX: assume subnet is /24
+PREFIX="$(echo "$MYIP" | cut -d'.' -f1-3)"
+
+findpeer(){
+    local prefix="$1"
+    local me="$2"
+    for ip in {1..254}
+    do
+        [ "$me" == "${prefix}.${ip}" ] && continue
+        {
+            ping -c1 -W1  "${prefix}.${ip}" 2>&1 1>/dev/null && echo "${prefix}.${ip}"
+        } &
+    done
+    wait
+}
+exit 0
+findpeer "$PREFIX" "$MYIP"