我正在尝试发送名称为id.no和mac地址的请求。这个过程我需要做100次。我的意思是100个不同的名字和id.no和mac地址。我试过这样做。我希望输出为name1,1234567679和aa:bb:cc:dd:11:22。有人可以帮帮我吗。我已将我的代码和输出粘贴在
下面for i in range (1,10):
name = 'name'+str(i)
print name
id = 121333445500000
id += 1
print id
mac = "aa:bb:cc:dd:"
ee = 0
for j in range(0,9):
ee1 = '0'+str(ee + j)+':'
ff = 0
for k in range(0,10):
ff1 = ff+k
if ff1 < 10:
mac1 = mac + ee1 + '0' + str(ff1)
print mac1
else:
mac1 = mac + ee1 + str(ff1)
print mac1
输出:
name1
121333445500001
aa:bb:cc:dd:00:00
aa:bb:cc:dd:00:01
aa:bb:cc:dd:00:02
aa:bb:cc:dd:00:03
aa:bb:cc:dd:00:04
aa:bb:cc:dd:00:05
aa:bb:cc:dd:00:06
aa:bb:cc:dd:00:07
aa:bb:cc:dd:00:08
aa:bb:cc:dd:00:09
aa:bb:cc:dd:01:00
aa:bb:cc:dd:01:01
aa:bb:cc:dd:01:02
aa:bb:cc:dd:01:03
aa:bb:cc:dd:01:04
aa:bb:cc:dd:01:05
aa:bb:cc:dd:01:06
aa:bb:cc:dd:01:07
aa:bb:cc:dd:01:08
aa:bb:cc:dd:01:09
aa:bb:cc:dd:02:00
aa:bb:cc:dd:02:01
aa:bb:cc:dd:02:02
aa:bb:cc:dd:02:03
aa:bb:cc:dd:02:04
aa:bb:cc:dd:02:05
aa:bb:cc:dd:02:06
aa:bb:cc:dd:02:07
aa:bb:cc:dd:02:08
aa:bb:cc:dd:02:09
aa:bb:cc:dd:03:00
aa:bb:cc:dd:03:01
aa:bb:cc:dd:03:02
aa:bb:cc:dd:03:03
aa:bb:cc:dd:03:04
aa:bb:cc:dd:03:05
aa:bb:cc:dd:03:06
aa:bb:cc:dd:03:07
aa:bb:cc:dd:03:08
aa:bb:cc:dd:03:09
aa:bb:cc:dd:04:00
aa:bb:cc:dd:04:01
aa:bb:cc:dd:04:02
aa:bb:cc:dd:04:03
aa:bb:cc:dd:04:04
aa:bb:cc:dd:04:05
aa:bb:cc:dd:04:06
aa:bb:cc:dd:04:07
aa:bb:cc:dd:04:08
aa:bb:cc:dd:04:09
aa:bb:cc:dd:05:00
aa:bb:cc:dd:05:01
aa:bb:cc:dd:05:02
aa:bb:cc:dd:05:03
aa:bb:cc:dd:05:04
aa:bb:cc:dd:05:05
aa:bb:cc:dd:05:06
aa:bb:cc:dd:05:07
aa:bb:cc:dd:05:08
aa:bb:cc:dd:05:09
aa:bb:cc:dd:06:00
aa:bb:cc:dd:06:01
aa:bb:cc:dd:06:02
aa:bb:cc:dd:06:03
aa:bb:cc:dd:06:04
aa:bb:cc:dd:06:05
aa:bb:cc:dd:06:06
aa:bb:cc:dd:06:07
aa:bb:cc:dd:06:08
aa:bb:cc:dd:06:09
aa:bb:cc:dd:07:00
aa:bb:cc:dd:07:01
aa:bb:cc:dd:07:02
aa:bb:cc:dd:07:03
aa:bb:cc:dd:07:04
aa:bb:cc:dd:07:05
aa:bb:cc:dd:07:06
aa:bb:cc:dd:07:07
aa:bb:cc:dd:07:08
aa:bb:cc:dd:07:09
aa:bb:cc:dd:08:00
aa:bb:cc:dd:08:01
aa:bb:cc:dd:08:02
aa:bb:cc:dd:08:03
aa:bb:cc:dd:08:04
aa:bb:cc:dd:08:05
aa:bb:cc:dd:08:06
aa:bb:cc:dd:08:07
aa:bb:cc:dd:08:08
aa:bb:cc:dd:08:09
name2
121333445500001
aa:bb:cc:dd:00:00
aa:bb:cc:dd:00:01
aa:bb:cc:dd:00:02
aa:bb:cc:dd:00:03
aa:bb:cc:dd:00:04
aa:bb:cc:dd:00:05
aa:bb:cc:dd:00:06
aa:bb:cc:dd:00:07
aa:bb:cc:dd:00:08
aa:bb:cc:dd:00:09
aa:bb:cc:dd:01:00
aa:bb:cc:dd:01:01
aa:bb:cc:dd:01:02
aa:bb:cc:dd:01:03
aa:bb:cc:dd:01:04
aa:bb:cc:dd:01:05
aa:bb:cc:dd:01:06
aa:bb:cc:dd:01:07
aa:bb:cc:dd:01:08
aa:bb:cc:dd:01:09
aa:bb:cc:dd:02:00
aa:bb:cc:dd:02:01
aa:bb:cc:dd:02:02
aa:bb:cc:dd:02:03
aa:bb:cc:dd:02:04
aa:bb:cc:dd:02:05
aa:bb:cc:dd:02:06
aa:bb:cc:dd:02:07
aa:bb:cc:dd:02:08
aa:bb:cc:dd:02:09
aa:bb:cc:dd:03:00
aa:bb:cc:dd:03:01
aa:bb:cc:dd:03:02
aa:bb:cc:dd:03:03
aa:bb:cc:dd:03:04
aa:bb:cc:dd:03:05
aa:bb:cc:dd:03:06
aa:bb:cc:dd:03:07
aa:bb:cc:dd:03:08
aa:bb:cc:dd:03:09
aa:bb:cc:dd:04:00
aa:bb:cc:dd:04:01
aa:bb:cc:dd:04:02
aa:bb:cc:dd:04:03
aa:bb:cc:dd:04:04
aa:bb:cc:dd:04:05
aa:bb:cc:dd:04:06
aa:bb:cc:dd:04:07
aa:bb:cc:dd:04:08
aa:bb:cc:dd:04:09
aa:bb:cc:dd:05:00
aa:bb:cc:dd:05:01
aa:bb:cc:dd:05:02
aa:bb:cc:dd:05:03
aa:bb:cc:dd:05:04
aa:bb:cc:dd:05:05
aa:bb:cc:dd:05:06
aa:bb:cc:dd:05:07
aa:bb:cc:dd:05:08
aa:bb:cc:dd:05:09
aa:bb:cc:dd:06:00
aa:bb:cc:dd:06:01
aa:bb:cc:dd:06:02
aa:bb:cc:dd:06:03
aa:bb:cc:dd:06:04
aa:bb:cc:dd:06:05
aa:bb:cc:dd:06:06
aa:bb:cc:dd:06:07
aa:bb:cc:dd:06:08
aa:bb:cc:dd:06:09
aa:bb:cc:dd:07:00
aa:bb:cc:dd:07:01
aa:bb:cc:dd:07:02
aa:bb:cc:dd:07:03
aa:bb:cc:dd:07:04
aa:bb:cc:dd:07:05
aa:bb:cc:dd:07:06
aa:bb:cc:dd:07:07
aa:bb:cc:dd:07:08
aa:bb:cc:dd:07:09
aa:bb:cc:dd:08:00
aa:bb:cc:dd:08:01
aa:bb:cc:dd:08:02
aa:bb:cc:dd:08:03
aa:bb:cc:dd:08:04
aa:bb:cc:dd:08:05
aa:bb:cc:dd:08:06
aa:bb:cc:dd:08:07
aa:bb:cc:dd:08:08
aa:bb:cc:dd:08:09
name3
121333445500001
答案 0 :(得分:1)
希望这会有所帮助
mac="0xaabbccdd0000"
for i in range(101):
mac = "{:012X}".format(int(mac, 16) + 1)
print(':'.join(mac[i]+mac[i+1] for i in range(0, len(mac), 2)))
答案 1 :(得分:0)
试试此代码
import time, random
mac = "aa:bb:cc:dd:"
for i in range(1,100):
name = 'name'+ str(i)
# getting random number for id
id = int(time.time()) + random.randrange(0, 100, 1)
# quotient in part 1
mac_end1 = "0" + str(int(i/10))
# remainder in part 2
mac_end2 = "0" + str(int(i%10))
mac1 = mac + mac_end1 + ":" + mac_end2
print name, id, mac1
答案 2 :(得分:0)
基于@tcpip,这里有一个更通用的方式
脚本文件名:mac_generator.py
#%%
import argparse
import sys
# sys.argv = ['']
parser = argparse.ArgumentParser()
parser.add_argument('-t',
'--total',
type=int,
default=100,
help="The total number of mac address to be generated")
parser.add_argument('-f',
'--file',
action="store_true",
help="Generate in filename mac_address.txt")
args = parser.parse_args()
print("Total number of MAC address to be generated is: {}".format(args.total))
#%%
mac="0x000000000001"
def print_mac():
for i in range(args.total - 1):
global mac
mac = "{:012X}".format(int(mac, 16) + 1)
print(':'.join(mac[i]+mac[i+1] for i in range(0, len(mac), 2)))
original_stdout = sys.stdout # Save a reference to the original standard output
if(args.file):
with open('mac_address.txt', 'w') as f:
sys.stdout = f # Change the standard output to the file we created.
print_mac()
sys.stdout = original_stdout # Reset the standard output to its origin
else:
print_mac()
用法
usage: mac_generator.py [-h] [-t TOTAL] [-f]
optional arguments:
-h, --help show this help message and exit
-t TOTAL, --total TOTAL
The total number of mac address to be generated
-f, --file Generate in filename mac_address.txt
因此,如果您想生成 100 个 MAC 地址,请运行 ./mac_generator -t 100