【问题标题】:Consuming bandwidth消耗带宽
【发布时间】:2010-07-29 14:56:49
【问题描述】:

我知道如何编写一个使用 wget 下载文件的基本 bash 脚本,但是如何在无限循环中运行它来下载指定的文件,下载完成后将其删除,然后再次下载。

【问题讨论】:

  • 消耗家庭互联网连接带宽 100%,直到程序/脚本被杀死。
  • 您这样做是为了给某人带来麻烦,还是有正当的目的?这样做是有原因的,但通常不会这样表述。
  • 我正在尝试从我自己的服务器上的家用计算机上执行此操作。没有恶意。现在我重新阅读了我的问题,听起来确实很恶意,哈哈。但老实说,我没有这样的意图。
  • 消耗带宽,很简单。找出它何时完全耗尽,这是困难的部分。可能是超时?

标签: linux bash command-line ubuntu debian


【解决方案1】:

你正在寻找

while :
do
    wget -O - -q "http://some.url/" > /dev/null
done

这不会保存文件,不会输出无用的信息,并将内容一遍又一遍地转储到/dev/null

编辑只消耗带宽,使用ping -fping -f -s 65507

【讨论】:

  • 我了解你的第一个脚本,但是 ping -f 或 ping -f -s 65507 是做什么的?
  • -f代表flood pinging,-s 65507设置包大小为65507字节
  • 确实如此,而且你不会让它变得更大,因为 65507 + 8 (icmp header) + 20 (ip header) 就是 65535(或 0xffff),这是你可以发送的最大 ipv4 数据包. (注意在上线之前会被切碎)
  • ping -f -s 1472 可能会更好,因为它不会碎片化。 (假设 1500 MTU,这在现在很正常。如果你在与服务器的千兆网络上可能会更高。在 PPPoE 上可能会更低。)
  • @derobert 你知道什么是 8kb/s 的 '.'看起来像在终端? ;-)
【解决方案2】:

如果您的目标是最大化带宽,尤其是为了进行基准测试,请使用iperf。您在服务器和客户端上运行iperf,它将使用您指定的协议和参数测试您的带宽。它可以测试单向或双向吞吐量,并且可以选择尝试实现“目标”带宽利用率(即 3Mbps)。

【讨论】:

  • 这很奇怪,我的家庭系统上没有不受信任的存储库,但是这个包却是不受信任的......
  • @oshiorwanen :那么要么包未签名,要么您实际上有不受信任的存储库,要么您的 gpg 有问题。无论如何,这是您的设置问题而不是程序问题。 iperf 旨在完成您正在做的事情,它既灵活又出色。
  • @oshirowanen: 运行另一个apt-get update,可能是上次下载Release文件出错了。
【解决方案3】:

编程一切皆有可能。 :)

如果您想尝试最大化您的互联网带宽,您可以启动许多 wget 进程,让它们同时下载一些大磁盘映像文件,同时将一些大文件发送回某个服务器.

细节留待实施,但这是最大化带宽的一种方法。

【讨论】:

  • 听起来很有趣,我知道如何编写基本脚本来使用 wget 下载东西,但是我如何让它一遍又一遍地下载,删除已经下载的版本,然后再下载?
【解决方案4】:

如果您想消耗网络带宽,则需要另一台计算机。然后从计算机 A,IP 192.168.0.1,监听一个端口(例如 12345)。

$ netcat -l -p 12345

然后,从另一台计算机向它发送数据。

$ netcat 192.168.0.1 12345 < /dev/zero

【讨论】:

  • 我想尝试最大化互联网连接。
  • 可靠地消耗最大带宽最好使用ping -f。问题是关于wget
  • 您能解释一下 ping -f 的作用吗?即它如何消耗带宽?
【解决方案5】:

我更喜欢使用 curl 来获取 wget。它更可编辑。这是我编写的 bash 脚本的摘录,它检查 SVN 版本,然后让用户选择下载稳定版或最新版。然后它解析文件,将“用户设置”与脚本的其余部分分开。

     svnrev=`curl -s -m10  mythicallibrarian.googlecode.com/svn/trunk/| grep -m1 Revision |  sed s/"<html><head><title>mythicallibrarian - "/""/g|  sed s/": \/trunk<\/title><\/head>"/""/g`

if ! which librarian-notify-send>/dev/null && test "$LinuxDep" = "1"; then
    dialog --title "librarian-notify-send" --yesno "install librarian-notify-send script for Desktop notifications?" 8 25
    test $? = 0 && DownloadLNS=1 || DownloadLNS=0
    if [ "$DownloadLNS" = "1" ]; then
        curl "http://mythicallibrarian.googlecode.com/files/librarian-notify-send">"/usr/local/bin/librarian-notify-send"
        sudo chmod +x /usr/local/bin/librarian-notify-send
    fi
fi

if [ ! -f "./librarian" ]; then
    DownloadML=Stable
    echo "Stable `date`">./lastupdated
else

 lastupdated="`cat ./lastupdated`"
DownloadML=$(dialog --title "Version and Build options" --menu "Download an update first then Build mythicalLibrarian" 10 70 15 "Latest" "Download and switch to SVN $svnrev" "Stable" "Download and switch to last stable version"  "Build"  "using: $lastupdated" 2>&1 >/dev/tty) 
if [ "$?" = "1" ]; then
    clear
    echo "mythicalLibrarian was not updated."
    echo "Please re-run mythicalSetup."
        echo "Done."
    exit 1
fi
fi
clear
if [ "$DownloadML" = "Stable" ]; then
    echo "Stable "`date`>"./lastupdated"
    test -f ./mythicalLibrarian.sh && rm -f mythicalLibrarian.sh
    curl "http://mythicallibrarian.googlecode.com/files/mythicalLibrarian">"./mythicalLibrarian.sh"
    cat "./mythicalLibrarian.sh"| sed s/'   '/'\\t'/g |sed s/'\\'/'\\\\'/g   >"./mythicalLibrarian1" #sed s/"\\"/"\\\\"/g |
    rm ./mythicalLibrarian.sh
    mv ./mythicalLibrarian1 ./mythicalLibrarian.sh
    parsing="Stand-by Parsing mythicalLibrarian"
    startwrite=0
    test -f ./librarian && rm -f ./librarian
    echo -e 'mythicalVersion="'"`cat ./lastupdated`"'"'>>./librarian
    while read line
    do
        test "$line" = "########################## USER JOBS############################" && let startwrite=$startwrite+1
        if [ $startwrite = 2 ]; then
            clear
            parsing="$parsing""."
            test "$parsing" = "Stand-by Parsing mythicalLibrarian......." && parsing="Stand-by Parsing mythicalLibrarian"
            echo $parsing
            echo -e "$line" >> ./librarian
        fi
    done <./mythicalLibrarian.sh

    clear
    echo "Parsing mythicalLibrarian completed!"
    echo "Removing old and downloading new version of mythicalSetup..."
    test -f ./mythicalSetup.sh && rm -f ./mythicalSetup.sh
    curl "http://mythicallibrarian.googlecode.com/files/mythicalSetup.sh">"./mythicalSetup.sh"
    chmod +x "./mythicalSetup.sh"
    ./mythicalSetup.sh
    exit 0

fi
if [ "$DownloadML" = "Latest" ]; then
    svnrev=`curl -s  mythicallibrarian.googlecode.com/svn/trunk/| grep -m1 Revision |  sed s/"<html><head><title>mythicallibrarian - "/""/g| sed s/": \/trunk<\/title><\/head>"/""/g`
    echo "$svnrev "`date`>"./lastupdated"
    test -f ./mythicalLibrarian.sh && rm -f mythicalLibrarian.sh
    curl "http://mythicallibrarian.googlecode.com/svn/trunk/mythicalLibrarian">"./mythicalLibrarian.sh"
    cat "./mythicalLibrarian.sh"| sed s/'   '/'\\t'/g |sed s/'\\'/'\\\\'/g   >"./mythicalLibrarian1" #sed s/"\\"/"\\\\"/g |
    rm ./mythicalLibrarian.sh
    mv ./mythicalLibrarian1 ./mythicalLibrarian.sh
    parsing="Stand-by Parsing mythicalLibrarian"
    startwrite=0
    test -f ./librarian && rm -f ./librarian
    echo -e 'mythicalVersion="'"`cat ./lastupdated`"'"'>>./librarian
    while read line
    do
        test "$line" = "########################## USER JOBS############################" && let startwrite=$startwrite+1
        if [ $startwrite = 2 ]; then
            clear
            parsing="$parsing""."
            test "$parsing" = "Stand-by Parsing mythicalLibrarian......." && parsing="Stand-by Parsing mythicalLibrarian"
            echo $parsing
            echo -e "$line" >> ./librarian
        fi
    done <./mythicalLibrarian.sh

    clear
    echo "Parsing mythicalLibrarian completed!"
    echo "Removing old and downloading new version of mythicalSetup..."
    test -f ./mythicalSetup.sh && rm -f ./mythicalSetup.sh
    curl "http://mythicallibrarian.googlecode.com/svn/trunk/mythicalSetup.sh">"./mythicalSetup.sh"
    chmod +x "./mythicalSetup.sh"
    ./mythicalSetup.sh
    exit 0

fi

编辑:没关系,我以为你在说它是在无限循环中下载

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多