我使用python程序在Linux Ubuntu中做流量生成器,代码如下:
import socket, sys
host = sys.argv[1] #Server IP Address
textport = sys.argv[2] #Server Binding Port
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #socket
try:
port = int(textport)
except ValueError:
port = socket.getservbyname(textport, 'udp')
while 1:
try:
data = open('auth3.log')#read file
for each_line in data: #each rows
try:
(role,line_spoken) = each_line.split(': ',1)#split two parts
role = role.strip()
s.sendto(role, (host, port))
print('Send: ' + str(role) + "\n" )
except:
pass
except IOError as err:
print('file isn\'t exist!!~'+str(err))
finally:
if 'data' in locals(): #If data have no object, Don't use data to close!!~
data.close()
print "\n"
auth3.log 的大小约为 1.8M。
当我向目标服务器发送数据时,我使用 OID 为 ''ifInOctets'' 的 snmp 来获取流量信息。
但我重新计算以“Kbits”为单位的流量约为 128。
我如何使用这个程序将带宽填充到 1Gbits?(也就是说,我要填充带宽)
谢谢你的帮助。