Loading

Monday, January 25, 2010

simple C++ port scanner

This program takes an input and output file

input.txt => IP Addresses you wish to connect to
output.txt => Results of the scan

Run the program enter a starting port and ending port, have fun

Code:


#include
#include
#include
#include
#include
#include
using namespace std;

SOCKET sock;
ofstream outfile;

bool ConnectToHost(int PortNo, char* IPAddress) {

WSADATA wsadata;

int error = WSAStartup(0x0202, &wsadata);

if (error) {
return false;
}

if (wsadata.wVersion != 0x0202) {
WSACleanup();
return false;
}

SOCKADDR_IN target;

target.sin_family = AF_INET;
target.sin_port = htons (PortNo);
target.sin_addr.s_addr = inet_addr (IPAddress);

sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // create socket
if (sock == INVALID_SOCKET)
{
return false; // could not create the socket
}


if (connect(sock, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
{
cout << "false " << endl;
outfile << "false " << endl;
return false; //couldn't connect
}
else {
cout << "true " << endl;
outfile << "true " << endl;
return true; // success
}
}

void CloseConnection () {
if (sock)
closesocket(sock);

WSACleanup();
}



char *convertStringToChar(const string &str)
{
char *retPtr(new char[str.length() + 1]);

copy(str.begin(), str.end(), retPtr);
retPtr[str.length()] = '\0';

return retPtr;
}


int main()
{
string line;
int myport1;
int myport2;
int i;
cout << "\n\n";
cout << "Enter the starting PORT You wish to attempt a connection on, example: \t 21 \n" << endl;
cin >> myport1;
cout << "Enter the Ending PORT You wish to attempt a connection on, example: \t 25 \n" << endl;
cin >> myport2;
outfile.open("outfile.txt");
ifstream myfile("input.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline(myfile, line);
for (i = myport1; i <= myport2; i++)
{
ConnectToHost(i, convertStringToChar(line));
cout << i << " \t " << line << endl;
outfile << i << "\t" << line << endl;

}

}
myfile.close();
outfile.close();
}
else cout << "Unable to open file input.txt\n\n";
system("PAUSE");
return EXIT_SUCCESS;
}


--------------------------------------

oO0::::: Greetz and Thanks: :::::0Oo.
Tuhan YME
My Parents
SPYRO_KiD
K-159
lirva32

And Also My LuvLy :
..::.E.Z.R (The deepest Love I'v ever had..).::..

in memorial :
1. Monique (terima kasih atas semua kenangan terindah yang pernah kau berikan)
MAAFKAN ATAS SEMUA DOSA DAN SALAHKU
2. Dewi S.
3. W. Devi Amelia
4. S. Anna

oO0:::A hearthy handshake to: :::0Oo
~ Crack SKY Staff
~ Echo staff
~ antijasakom staff
~ jatimcrew staff
~ whitecyber staff
~ lumajangcrew staff
~ unix_dbuger, boys_rvn1609, jaqk, byz9991, bius, g4pt3k, anharku, wandi, 5yn_4ck, kiddies, bom2
~ arthemist, opt1lc, m_beben, gitulaw, luvrie, poniman_coy, ThePuzci, x-ace, newbie_z, petunia, jomblo.k, hourexs_paloer, cupucyber, kucinghitam, black_samuraixxx, ucrit_penyu, wendys182, cybermuttaqin
~ k3nz0, thomas_ipt2007, blackpaper, nakuragen, candra
~ whitehat, wenkhairu, Agoes_doubleb, diki, lumajangcrew a.k.a adwisatya a.k.a xyberbreaker, wahyu_antijasakom
~ All people in SMAN 3
~ All members of spyrozone
~ All members of echo
~ All members of newhack
~ All members of jatimcrew
~ All members of Anti-Jasakom
~ All members of whitecyber
#e-c-h-o, #K-elektronik, #newhack, #Solohackerlink, #YF, #defacer, #manadocoding, #jatimcrew, #antijasakom, #whitecyber

0 komentar:

Categories

Stats

kumpulblogger