1.制造非法ip流程如下:
2.代码如下
import threading
ipWrittenFlag = False
# lockA = threading.Lock()
c = threading.Condition()
fileObject = open('illegalIp.txt', 'w')
def create_illegal_ip():
list1 = []
for i in range(100):
list2 = []
for j in range(4):
while True:
random_char_list = random.sample('0123456789', 3)
random_ip_piece_string = ''.join(random_char_list)
if (int(random_ip_piece_string) <= 256) & ((random_ip_piece_string[0]) != 0):
list2.append(random_ip_piece_string)
break
list1.append('.'.join(list2))
print(list1)
# lockA.acquire()
c.acquire()
for ip in list1:
fileObject.write(ip)
fileObject.write('\n')
global ipWrittenFlag
ipWrittenFlag = True
c.notify_all()
c.release()
# lockA.release()
def create_illegal_ip_of_all_strings():
global Flag
list3 = []
for i in range(100):
list4 = []
for j in range(4):
random_char_list = random.sample('abcdefghijklmnopqrstuvwxyz1234567890~`!@#$%^&*()_-+=\|、}{][;:?/><,.', 3)
random_ip_piece_string = ''.join(random_char_list)
list4.append(random_ip_piece_string)
list3.append('.'.join(list4))
print(list3)
c.acquire()
if not ipWrittenFlag:
c.wait()
# if (Flag == True):
for ip in list3:
fileObject.write(ip)
fileObject.write('\n')
threading1 = threading.Thread(target=create_illegal_ip, name="threading1")
threading2 = threading.Thread(target=create_illegal_ip_of_all_strings, name="threading2")
threading1.start()
threading2.start()
threading1.join()
threading2.join()
fileObject.close()
3.print的结果如下:
['187.237.172.218', '083.061.062.052', '054.039.039.246', '240.145.203.248', '105.079.180.205', '057.012.043.182', '235.215.109.108', '056.251.187.197', '074.056.036.054', '247.168.152.207', '130.156.238.107', '246.214.102.156', '098.237.164.249', '129.215.146.154', '012.189.198.136', '023.216.218.081', '194.069.201.108', '218.059.085.102', '253.018.210.036', '254.204.015.085', '237.167.164.023', '247.062.014.135', '043.147.190.168', '069.218.168.049', '092.135.037.094', '076.014.047.135', '214.189.207.174', '068.069.058.071', '108.186.012.170', '083.139.156.125', '012.182.039.028', '081.239.168.237', '017.068.183.014', '240.108.159.083', '238.068.208.149', '084.248.125.127', '235.139.058.214', '236.071.064.106', '059.184.172.026', '152.029.231.217', '217.057.016.076', '079.137.052.201', '253.139.128.061', '159.253.130.127', '180.023.249.175', '139.135.198.089', '183.124.129.043', '096.056.072.081', '157.023.128.128', '067.238.136.018', '013.029.013.049', '156.197.134.178', '091.068.246.026', '179.215.089.096', '062.043.245.048', '056.138.189.173', '180.205.182.028', '102.201.210.058', '029.216.176.056', '176.243.098.109', '059.024.157.132', '236.019.175.246', '106.245.182.127', '072.249.018.254', '175.180.049.246', '235.073.023.105', '146.024.172.065', '069.023.046.256', '192.209.189.075', '032.038.250.032', '246.203.037.095', '046.135.218.087', '213.058.164.136', '047.230.067.041', '023.146.052.237', '106.210.039.108', '025.124.097.051', '016.024.012.135', '203.096.207.069', '092.019.145.142', '057.018.012.082', '027.169.256.065', '043.231.051.143', '017.092.165.042', '172.165.103.047', '045.095.036.193', '138.189.032.174', '204.012.075.086', '094.147.140.091', '018.067.176.037', '217.126.132.142', '043.158.059.231', '214.179.162.248', '162.103.136.068', '076.039.016.195', '129.045.248.217', '167.074.189.031', '164.190.130.025', '087.095.076.015', '143.026.018.168']['kw|..!p.d#6.}+3', 'ew|.xc-.6]@.ow+', '=8r.5z<.pwk.s|i', '1~@.0;k.+}%.dm;', '=4#.gr:.+<y.wy8', 'iu7._=+.u2z.`.,', 'svn.*kr.w-b.9qb', ']$v.w{n.|4$.9}w', '(i8.w1<.t{i.&h{', 'z、c.ry}.|g[.7_+', '#+o.\\,j.、[e.d#a', '>a}.}7~.$5f.x;、', 'ky{.0)、.e-(.i-k', '$@1.1.、.i]、.imp', ')pk.ex5.!u2.=y>', '^}a.u+a.<s6.\\m&', '9qi.hc4.^.{.[+2', '&[k.[/,.rw!.6#%', 'l$\\.^h{.eo6.(c.', '?x^.6b>.\\n`.wp=', '0j8.5%6.@/>.<&]', '7r?.p^;.}(y..m、', '$<`.#i3.e8q.yu4', '-]@./@w.!#k.(?`', '0j_.i2>.$_~.[7y', '#xq.(]9.(%b.+k!', '2!3.7、h.s@%.s]6', 'y、^.e[1.5my.、#s', ';j?.84、.cv/.sw、', '9^4.p?_.]=、.<t?', 'tq、.7$w.i;&.]{、', 'zm^.uz4.3_).sdo', 'sj..}i&.-9d.3<w', '$y-.b(v.@f、._z%', '8,(.qa5.n{_.57o', '.xr..]w.dn~.<sh', 'pi..t\\r.$-].n%s', 'jo`.un<.gyh.7o=', 'j?}.$,a.f2@._f0', '?;=.{@:.o\\&.:t/', 'h-k.k~u.h2{.{h=', '3=u.-`^.|10.8~i', 'a7~.svn.,x0.usv', ',:m.a~y.]nh.|~v', 'q4#.(2-.(<>.lt?', '<r(.d5,.、#6.jxe', 'jv/.,a8.@f\\.+r#', '/6q.u0:.4(6.、={', ']2h.3=,.zd>.iyr', 'n(3.3|#.qpi.rl>', 'yv8.4h}./%6.\\*)', '2:f.m%$.o~+.-7#', '`|>.^m2.4^>.5u:', '$b8.#di.;f`.?vi', 'j#..tko.@0&.fun', '83$.5*、.j\\{.^nd', ']%u.,5v.r~5.%]5', 'g7$.?(7.<;l.pf@', '<6{.、=?.)?r.?>[', 'dfw.=y3.ot+.@=,', '9\\w.#aw.,h&.c1%', 'xb(.16z._=b.9:=', '}@y.=j1._p$.kh\\', 'u3z.@^e.c;n.t35', 'j|0.mf#.-&s.+s;', '/v%.u#q.0eu.s*z', 'xe+.t,d.#2k.!@)', '(h/.0&u.3.g.75=', 't:*.{to.6k&.t/o', 'r=q.5ci.]@v.~w]', 'b4n.nz1.~,g.{4(', '$!..3o4.hyf.cfw', 'b0,.t&!.l*;.i}/', 't;k.>/-.`0@.4<o', '}k;.o9-.s7].@+$', 'a>u.\\9~.z:q.u&,', ':f{.s)<.09d.|(%', 'wi$./}r.v、j.bdp', '、c_.,%=.c(5.~-#', 'yiv.d2:.f@!.~p#', 'k8r.=16.<db.h\\}', '、@g.0md.1$}.l>k', '[xa.$9r.!\\0.g(-', 'e^a.a3j.5%z.&-k', 'g!).!%-.d]n.,9o', 'ig%.m|(.?v5.)nw', 'm]9.、#`.>、g.h7z', '?+:.b1;.)/7.qr2', '-yl.}\\_.$,q.|!q', 'p_4.dg+.3、e.~eq', 'v+|.ce>.$5i.k/、', 'mf$.pe1.$g#.01:', '+uf.:=t.tv2.[?.', 's^m.qy*.{+j.ofs', 'li[.=9u.t=n.#ni', '-x7.2)^.g=7./,8', '<:6.r、<.]$z.|)=', '&/v.w?/.tm5.\\|e', '|n[.gl4.!w9.geu', 'e@c.ub%.,|h.+h\\']