Heim  >  Fragen und Antworten  >  Hauptteil

python – Ein Multithreading-Neuling möchte fragen, wie man Multithread-Druck mit einer solchen IP implementieren kann?

def hanshu(b):
    print(b)

a="192.168.1.1-3"
for ip in a.split(','):
    if '-' in ip:
        s1, s2 = ip.rsplit('.', 1)
        start, end = map(int, s2.split('-'))
        for num in range(start, end+1):
            b=s1+'.'+str(num)
            hanshu(b)
    else:
        hanshu(ip)
PHPzPHPz2701 Tage vor855

Antworte allen(2)Ich werde antworten

  • 黄舟

    黄舟2017-05-27 17:41:49

    https://pypi.python.org/pypi/IPy/

    使用这个模块,你的代码不会这么难看,而且
    split(",") 写错了

    Antwort
    0
  • 黄舟

    黄舟2017-05-27 17:41:49

    多线程要用的threading模块吧,不是很明白你要什么

    Antwort
    0
  • StornierenAntwort