LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2973|回复: 1

请大家帮我看看pktgen是怎么玩的?

[复制链接]
发表于 2004-4-15 10:00:39 | 显示全部楼层 |阅读模式
How to use the Linux packet generator module.

1. Enable CONFIG_NET_PKTGEN to compile and build pktgen.o, install it
   in the place where insmod may find it.
2. Cut script "ipg" (see below).
3. Edit script to set preferred device and destination IP address.
3a.  Create more scripts for different interfaces.  Up to thirty-two
     pktgen processes can be configured and run at once by using the
     32 /proc/net/pktgen/pg* files.
4. Run in shell: ". ipg"
5. After this two commands are defined:
   A. "pg" to start generator and to get results.
   B. "pgset" to change generator parameters. F.e.
      pgset "clone_skb 100"   sets the number of coppies of the same packet
                              will be sent before a new packet is allocated
      pgset "clone_skb 0"     use multiple SKBs for packet generation
      pgset "pkt_size 9014"   sets packet size to 9014
      pgset "frags 5"         packet will consist of 5 fragments
      pgset "count 200000"    sets number of packets to send, set to zero
                              for continious sends untill explicitly
                              stopped.
      pgset "ipg 5000"        sets artificial gap inserted between packets
                              to 5000 nanoseconds
      pgset "dst 10.0.0.1"    sets IP destination address
                              (BEWARE! This generator is very aggressive!)
      pgset "dst_min 10.0.0.1"            Same as dst
      pgset "dst_max 10.0.0.254"          Set the maximum destination IP.
      pgset "src_min 10.0.0.1"            Set the minimum (or only) source IP.
      pgset "src_max 10.0.0.254"          Set the maximum source IP.
      pgset "dstmac 00:00:00:00:00:00"    sets MAC destination address
      pgset "srcmac 00:00:00:00:00:00"    sets MAC source address
      pgset "src_mac_count 1" Sets the number of MACs we'll range through.  The
                              'minimum' MAC is what you set with srcmac.
      pgset "dst_mac_count 1" Sets the number of MACs we'll range through.  The
                              'minimum' MAC is what you set with dstmac.
      pgset "flag [name]"     Set a flag to determine behaviour.  Current flags
                              are: IPSRC_RND #IP Source is random (between min/max),
                                   IPDST_RND, UDPSRC_RND,
                                   UDPDST_RND, MACSRC_RND, MACDST_RND
      pgset "udp_src_min 9"   set UDP source port min, If < udp_src_max, then
                              cycle through the port range.
      pgset "udp_src_max 9"   set UDP source port max.
      pgset "udp_dst_min 9"   set UDP destination port min, If < udp_dst_max, then
                              cycle through the port range.
      pgset "udp_dst_max 9"   set UDP destination port max.
      pgset stop                  aborts injection
      
  Also, ^C aborts generator.

---- cut here

#! /bin/sh

modprobe pktgen

PGDEV=/proc/net/pktgen/pg0

function pgset() {
    local result

    echo $1 > $PGDEV

    result=`cat $PGDEV | fgrep "Result: OK:"`
    if [ "$result" = "" ]; then
         cat $PGDEV | fgrep Result:
    fi
}

function pg() {
    echo inject > $PGDEV
    cat $PGDEV
}

pgset "odev eth0"
pgset "dst 0.0.0.0"

---- cut here

这是自带的说明文档
我设好了
pgset "pkt_size 64"  
pgset "frags 5"
pgset "count 200000"
pgset "ipg 5000"
pgset "dst 172.16.200.212"
pgset "src_min 172.16.200.211"
pgset "dstmac 00:03:47:963:F0"
pgset "srcmac 00:03:47:98:6B:2F"
运行ipg
但是好像没有任何反应也!
哪一个才是产生包的程序呢?
 楼主| 发表于 2004-4-15 10:44:02 | 显示全部楼层
赫赫,知道了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表