gpt4 book ai didi

linux - ./pingscript.sh - Georgia Weidmann 的书

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:50:35 27 4
gpt4 key购买 nike

我正在尝试根据 Georgia Wiedmann 的书创建一个 bash 脚本。我的 XP 目标计算机和 Kali 计算机已启动并正在运行。

#!/bin/bash
if [ "$1" == "" ]
then
echo "Usage: ./pingscript.sh [network]"
echo "example: ./pingscript.sh 192.168.x.x"
else
for x in 'seq 1 254'; do
ping -c 1 $1.$x | grep "64 bytes" | cut -d" " -f4 | sed 's/.$//'
done
fi

我不知道 8.8.8.8 应该是我的 XP 的 IP 还是网关地址,但是当我这样做时 ./pingscript.sh 192.168.x.x 我应该是收到响应,但它显示的是 Ping unknown host

有人帮忙吗?

最佳答案

这是 shellcheck :

Line 7:
for x in 'seq 1 254'; do
^-- SC2041: This is a literal string. To run as a command, use $(..) instead of '..' .

引用其 wiki :

The intent was to run the code in the single quotes. This would have worked with slanted backticks, `..`, but here the very similar looking single quotes '..' were used, resulting in a string literal instead of command output.

This is one of the many problems with backticks, so it's better to use $(..) to expand commands.

换句话说,使用:

for x in $(seq 1 254); do

关于linux - ./pingscript.sh - Georgia Weidmann 的书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50496259/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com