Created
May 16, 2013 06:19
-
-
Save wendal/5589738 to your computer and use it in GitHub Desktop.
查找同网段的linux主机
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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