search

Home  >  Q&A  >  body text

python - A multi-threading novice would like to ask how to implement multi-threaded printing with such an IP?

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)
PHPzPHPz2835 days ago924

reply all(2)I'll reply

  • 黄舟

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

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

    Use this module, your code will not be so ugly, and
    split(",") is written wrong

    reply
    0
  • 黄舟

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

    The threading module is used for multi-threading. I don’t quite understand what you want

    reply
    0
  • Cancelreply