Tcl/keep CT automated test script instance 7-packet Construction Test

Source: Internet
Author: User
Tags echo command

I mentioned earlier the idea of using Nemesis to construct packets for testing. Today I will introduce such a script.
The function of this script is to construct and send packets with different MAC addresses. With this script, we can test the maximum number of MAC addresses that can be learned on each port of the switch.

To put it simply, Nemesis runs on Linux or windows. In Linux, you must have the root permission to construct packets.
It can be used to construct packets of ARP, enternet, IP, ICMP, IGMP, DNS, TCP, OSPF, Rip, and other types. In fact, you can use a file as the content of the packets it constructs. From this perspective, it can be used to construct any type of packets.
In addition, because it is a group of tools based on command line, it can be used in combination with Tcl/CT to complete automated testing.

This script is still called by the test. Exp script described earlier. The call method is as follows:
./Test. exp-ssrc_mac_attack.exp script

The content of this script file (src_mac_attack.exp) is as follows:

# $ ID $
# Construct different source MAC address packets, and send them to switch.

Proc src_mac_attack {Mac }{
Set RC [exec echo "src Mac Attack Packet $ Mac "/
| Nemesis Ethernet-M 00: 01: 02: 03: 04: 05-h $ Mac-T 0x0800-p-]
Return $ RC
}

For {set I 1 }{$ I <256} {incr I }{
Set Mac [constructmac $ I]
Src_mac_attack $ Mac
}

The script is very simple. There is only one loop, and a new Mac is generated continuously, and then packets are sent.
A Brief Introduction to proc src_mac_attack. In this function, execute commands in Linux using the exec command of TCL. The Linux Command executed here is:
Echo "src Mac Attack Packet $ Mac "/
| Nemesis Ethernet-M 00: 01: 02: 03: 04: 05-h $ Mac-T 0x0800-p-
Among them, the echo command output is sent to the Nemesis command for input through the pipeline, and the content displayed by the echo command will be the content of the constructed Ethernet packet;
The Nemesis Ethernet command indicates that an Ethernet packet is constructed.-M,-h, and-T indicate the destination address, source address, and type of the packet respectively. "-P-" indicates that the content of the message is obtained from the standard input. In this example, it is the output of the ECHO command.

The script calls another user-defined function, which is placed in commonlib. in exp, it is used to generate a MAC address (up to 65535 non-repeated MAC addresses can be generated). The function content is as follows, which is relatively simple and will not be repeated:

#*************************************** *********
# Construct MAC address
#
# @ Params
# Rawmac --- raw MAC address, integer
#
# @ Return
# The MAC address string
#*************************************** *********
Proc constructmac {rawmac }{
Set Mac "00: 00: 00: 00"
Set J [expr "($ rawmac> 8) & 0xff"]
Set K [format "% x" $ J]
Set Mac "$ Mac: $ K"
Set J [expr "$ rawmac & 0xff"]
Set K [format "% x" $ J]
Set Mac "$ Mac: $ K"

Dbglog "rawmac = $ rawmac, MAC = $ Mac"
Return $ Mac
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.