home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-06-07 | 3.6 KB | 124 lines |
- /*
- * Java Port Scanner
- *
- * Copyright 2000 Matteo Baccan <mbaccan@planetisa.com>
- * www - http://www.infomedia.it/artic/Baccan
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA (or visit
- * their web site at http://www.gnu.org/).
- *
- */
-
- import java.net.*;
- import java.util.*;
- import java.io.*;
-
- public class port {
- private static Vector aServices = new Vector();
-
- public port(){}
-
- public void setFile( String cFile ){
- try{
- RandomAccessFile RAF;
- RAF = new RandomAccessFile( cFile, "r" );
-
- String cLine = "";
- cLine = RAF.readLine();
- while( cLine!=null ){
- aServices.addElement( new subService( cLine ) );
- cLine = RAF.readLine();
- }
- RAF.close();
- } catch ( Throwable e) {
- System.out.println( "\nError during opening of " +cFile +" : " +e.toString() );
- e.printStackTrace();
- }
- }
- public void setRange( int nPortFrom, int nPortTo ){
- for( int nPort=nPortFrom; nPort<=nPortTo; nPort++ ){
- aServices.addElement( new subService( "+," +nPort +",???,???,," ) );
- }
- }
- /*
- static int toNumber( String cService ){
- int nRet = 0;
- int nPos = 0;
- while( nPos<aServices.size() ){
- if( ((subService)aServices.elementAt(nPos)).equals( cService ) ){
- nRet = aServices[nPos].nPort;
- break;
- }
- nPos++;
- }
- return nRet;
- }
-
- static String toString( int nService ){
- String cRet = new Integer( nService ).toString();
- int nPos = 0;
- while( nPos<aServices.length ){
- if( aServices[nPos].equals( nService ) ){
- cRet = aServices[nPos].cDesc;
- break;
- }
- nPos++;
- }
- return cRet;
- }
- */
- static int length() {
- return (aServices.size());
- }
-
- static int getPort( int nPos ) {
- return ((subService)aServices.elementAt(nPos)).nPort;
- }
- static String getDesc( int nPos ) {
- return ((subService)aServices.elementAt(nPos)).cShortDesc +" - " +
- ((subService)aServices.elementAt(nPos)).cLongDesc;
- }
- }
-
- class subService {
- public boolean toScan = false;
- public int nPort;
- public String cShortDesc;
- public String cLongDesc;
-
- public subService( String cService ){
- StringTokenizer token = new StringTokenizer( cService, "," );
-
- if( token.hasMoreTokens() ){
- toScan = token.nextToken().equalsIgnoreCase("+");
- }
- if( token.hasMoreTokens() ){
- nPort = Integer.parseInt( token.nextToken() );
- }
- if( token.hasMoreTokens() ){
- cShortDesc = token.nextToken();
- }
- if( token.hasMoreTokens() ){
- cLongDesc = token.nextToken();
- }
- }
- public boolean equals( String cService ){
- return cLongDesc.equalsIgnoreCase( cService );
- }
- public boolean equals( int nService ){
- return (nPort==nService);
- }
- }
-