#! /usr/bin/env python # # Coded by syn|ack # # Usage: fscan.py [input list] [output list] # # Thanks largely to the makers of python for a great scripting language. # Props to pROcon, Firetrack, Bedlam, Trend_Killa, Ledge and # stormbringer9 @ #HackerzLair on DALnet # import sys, string, signal from socket import * # Hardcode the finger port as it is not likely to change FINGER_PORT = 79 # Hardcode the size of the receive buffer BUFFSIZE = 1024 # Set Connection timeout time of 10 seconds CONNECTION_TIMEOUT = 5 # Set a Read data timeout time of 30 seconds READ_TIMEOUT = 30 class FingerHost: # A class that fingers a host def __init__( self, host ): # A constructor. # self.host = host self.sock = socket( AF_INET, SOCK_STREAM ) def _connectHost( self ): # Connect to a host. # # The host is the host that was constructed with the constructor. # The port is always the same. # signal.signal( signal.SIGALRM, handler ) signal.alarm( CONNECTION_TIMEOUT ) self.sock.connect( self.host, FINGER_PORT ) signal.alarm( 0 ) def _finger( self ): # Finger the host. # # Sends \n to the remote host, which is the same as something # like @ to get a full list. # self.sock.send( '\n' ) def _recvData( self, fileOut ): # Recieve data from our remote host. # # Receives data in 1024 byte chunks. Any data returned by the # host is placed in a user defined output file. # fullBuf = '' signal.signal( signal.SIGALRM, handler ) signal.alarm( READ_TIMEOUT ) buf = self.sock.recv( BUFFSIZE ) fullBuf = fullBuf + buf while ( len( buf ) == BUFFSIZE ): buf = self.sock.recv( BUFFSIZE ) fullBuf = fullBuf + buf signal.alarm( 0 ) fileOut.write( '<< ' + self.host + ' >>\n' ) fileOut.write( '\t' + fullBuf ) def _closeSocket( self ): # Close the socket. # self.sock.close() def handler( signum, frame ): pass def main(): if len( sys.argv ) < 3: sys.exit( "Usage: fscan.py [input list] [output list]" ) fIn = sys.argv[ 1 ] fOut = sys.argv[ 2 ] fileIn = open( fIn, 'r' ) fileOut = open ( fOut, 'w' ) fileError = open ( 'fscanError.log', 'w' ) while 1: host = fileIn.readline() if not host: break host = string.split( host, '\n' ) target = FingerHost( host[ 0 ] ) try: # set the connection timeout to 30 seconds target._connectHost() target._finger() target._recvData( fileOut ) target._closeSocket() except error: fileError.write( "Can't connect to " + host [ 0 ] + '\n' ) pass del target fileOut.close() main()