Регистрация Главная Сообщество
Сообщения за день Справка Регистрация

Ответ
 
Опции темы
Старый 03.07.2009, 19:30   #1
Заблокирован
 Пехотинец
Аватар для Silence
 
Silence скоро будет известенSilence скоро будет известенSilence скоро будет известенSilence скоро будет известен
Регистрация: 17.06.2009
Сообщений: 60
Популярность: 382
Сказал(а) спасибо: 63
Поблагодарили 151 раз(а) в 49 сообщениях
 
По умолчанию сканер портов на C++

Код:
/**************************************
//     
// Name: A Simple but effective port sca
//     nner
// Description:This port scanner is pret
//     ty simple, it just fork()'s each connect
//     () call, and reads the return value.
// By: zer0python
//
//This code is copyrighted and has// limited warranties.Please see http://
//     www.Planet-Source-Code.com/vb/scripts/Sh
//     owCode.asp?txtCodeId=9664&lngWId=3//for details.//**************************************
//     

/* simple connect port scanner.. -- very fast .. very detectable... */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <netdb.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/poll.h>
static int verbose = 0;


    enum port_e {
    	P_ERROR = 0,
    	P_CLOSED = 1,
    	P_OPEN = 2,
};

enum port_e chkport(struct sockaddr_in addr);
//int v_printf(const char *fmt, ...);	/*
//     verbose printf */
#define v_printf(x)	if(verbose) printf x
int main(int argc, char *argv[])


    {
    	int index = 1, i;
    	struct sockaddr_in addr;
    	struct hostent *hp;


        	if(argc < 2) {
        		fprintf(stderr, "Usage:\n\t%s [-v] <host>\n", argv[0]);
        		return 0;
        	}
        	if((argv[1][0] == '-') && argv[1][1] == 'v')
        		verbose = index++;


            	if(index != 1 && argc == 2) {
            		fprintf(stderr, "missing host\n");
            		return 0;
            	}
            	hp = gethostbyname(argv[index]);


                	if(!hp) {
                		fprintf(stderr, "could not lookup host\n");
                		return 0;
                	}
                	memset(&addr, 0, sizeof(addr));
                	addr.sin_family = PF_INET;
                	memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);
                	printf("Scanning Host %s\n", argv[index]);
                	clock_t st = clock();


                    	for(i = 1; i <= 65535; i++) {
                    		addr.sin_port = htons(i);


                        		if(!fork()) {
                        			enum port_e p = chkport(addr);


                            			switch(p) {
                            				case P_OPEN: printf("%-4d OPEN\n", i); break;
                            				case P_CLOSED: if(verbose) printf("%-4d CLOSED\n", i); break;
                            				case P_ERROR: if(verbose) printf("%-4d ERROR\n", i); break;
                            			}
                            			exit(0);
                            		}
                            	}
                            	printf("Done in %.2lf seconds.\n", (float) (clock() - st) / CLOCKS_PER_SEC);
                            	return 0;
                        }

                        enum port_e chkport(struct sockaddr_in addr)


                            {
                            	int sd = socket(PF_INET, SOCK_STREAM, 0);
                            	enum port_e prtst = P_OPEN;
                            	if(sd < 0)
                            		return P_ERROR;
                            /*


                                	if(fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
                                		close(sd);
                                		return P_ERROR;
                                	}
                                */
                                	if(connect(sd, (struct sockaddr*) &addr, sizeof(addr)))
                                		return P_CLOSED;
                                	shutdown(sd, 2);
                                	close(sd);
                                	return prtst;
                            }
  Ответить с цитированием
Ответ


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход

Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
[Статья] Номера портов используемы RF SERVER AirLibra Rising Force Online 3 26.06.2009 20:06

Заявление об ответственности / Список мошенников

Часовой пояс GMT +4, время: 21:43.

Пишите нам: [email protected]
Copyright © 2024 vBulletin Solutions, Inc.
Translate: zCarot. Webdesign by DevArt (Fox)
G-gaMe! Team production | Since 2008
Hosted by GShost.net