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
}