0

WRT1900ac linky s の起動時に次のBASH スクリプトを実行しています。

USER="admin"
PASS="passhere"
PROTOCOL="http"
ROUTER_IP="192.168.1.1"

# Port to connect to which will provide the JSON data.
PORT=9898

while [ 1 ]
do
    # Grab connected device MAC addresses through router status page.
    MACS=$(curl -s --user $USER:$PASS $PROTOCOL://$ROUTER_IP/Status_Wireless.live.asp)

    # clear temp JSON file
    echo > temp.log

    # Get hostname and IP (just in case there is no hostname).
    for MAC in $(echo $MACS | grep -oE "wl_mac::[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}" | cut -c 9-);
    do
        grep 0x /proc/net/arp | awk '{print $1 " " $4}' | while IFS= read -r line
        do
        IP=$(echo $line | cut -d' ' -f1)
        MACTEMP=$(echo $line | cut -d' ' -f2)
        HOST=$(arp -a | grep $IP | cut -d' ' -f1)

        # if no hostname exists, just use IP.
        if [ "$HOST" == "" ]
        then
            HOST=$IP
        fi

        if [ "$MAC" == "$MACTEMP" ]
        then
            JSON="{'hostname' : '$HOST', 'mac_address' : '$MAC'}"
            echo $JSON >> temp.log
        fi

        done
    done

    # Provide the JSON formatted output on $PORT of router.
    # This allows one connection before closing the port (connect, receive data, close).
    # Port will reopen every 5 minutes with new data as setup in a cron job.
    echo -e "HTTP/1.1 200 OK\n\n $(cat temp.log)" | nc -l -p$PORT >/dev/null

    # Wait for 10 seconds and do it all over.
    sleep 10

done

そして、何らかの理由で、ルーターを再起動してからhttp://192.168.1.1:9898にアクセスしようとすると、Android携帯電話がWi-Fi経由でルーターに接続されていて、ルーターにMACアドレスが表示されているにもかかわらず、空白のページが表示されますステータスページに。

そのページには、現在ルーターに接続されているすべてのワイヤレス MAC アドレスが表示され、JSON形式で表示されます。

問題を特定するのに役立つ BASH の第一人者はいますか?

4

1 に答える 1

0

そうあるべきだと思う

echo -e "HTTP/1.1 200 OK\n\n $(cat temp.log)" | nc -l -p$PORT 0.0.0.0 >/dev/null

于 2016-11-19T18:53:08.807 に答える