Skip to content

Instantly share code, notes, and snippets.

@wendal
Created May 16, 2013 06:19
Show Gist options
  • Save wendal/5589738 to your computer and use it in GitHub Desktop.
Save wendal/5589738 to your computer and use it in GitHub Desktop.
查找同网段的linux主机
#!/usr/bin/python
'''
Created on 2013-4-20
@author: wendal
'''
import socket, threading, time
def main():
for n in range(1, 255) :
ip = "192.168.72.%d" % n #换上你需要的扫描的网段
PingThread(ip).start()
time.sleep(0.1)
class PingThread(threading.Thread):
def __init__(self, ip):
threading.Thread.__init__(self)
self.ip = ip
def run(self):
try:
socket.create_connection((self.ip, 22), 1).close()
print "%s OK" % self.ip
except:
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment