Exemplo Básico de Sockets em C
Publicado por Anderson L Tamborim 13/05/2004
[ Hits: 29.196 ]
Homepage: http://y2h4ck.wordpress.com
Download 1289838851.sock1.c (versão 2)
Pequeno script mostra um simples esquema de esboço de verificação se uma porta está aberta para conexão ou nao.
Principio de um port scan :) esse pega apenas as 30 primeiras portas ... apenas como Proof of concept. Enjoy
Versão 2 - Enviado por Felipe S. Araujo em 15/11/2010
Changelog: Apenas aprimorei a impressão das portas fechadas, mas se você achar que o scan deve apenas listar as portas abertas, comente a linha:
printf("A porta %d esta aberta\n",porta);
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/signal.h> #include <errno.h> #include <netdb.h> #define PORTA_INICIO 1 main(int argc, char *argv[]) { char host[15]; int porta, portas, i , spawnsocket, delay, ligacao; struct sockaddr_in alvo; struct hostent *he; struct servent *servicos; if ( argc == 1 ) { fprintf(stderr,"RootSec Scan V0.1\n"); fprintf(stderr,"usar: %s <host>\n",argv[0]); exit(0); } if ( argc > 1 ) { porta = PORTA_INICIO; } if (argc > 2 ) { porta = atoi (argv[2]); } he = gethostbyname ( argv[1] ); if ( he == NULL ) { printf("Host Nao encontrado"); exit(-1); } for(porta=1;porta<=30;porta++) { spawnsocket = socket( AF_INET, SOCK_STREAM, 0); if ( spawnsocket < 0) { perror("Socket"); } alvo.sin_family = he->h_addrtype; alvo.sin_port = htons(porta); alvo.sin_addr = *((struct in_addr *)he->h_addr); bzero(&(alvo.sin_zero),8); ligacao = connect ( spawnsocket, (struct sockaddr *) &alvo, sizeof(alvo)); if ( ligacao == -1 ) { perror("Porta esta fechada\n"); } else { printf("A porta %d esta aberta\n",porta); } close(spawnsocket); } }
Portscan Simples Usando Sockets em C
Exemplo de sockets: um client e um server bem simples
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Debian 13 Trixie para Iniciantes
Convertendo pacotes DEB que usam ZSTD (Padrão Novo) para XZ (Padrão Antigo)
Ajuda com o Debian 13 - Video hibrido geforce 940 mx Wayland OFF (1)
baschrc customizado pegeui vários. (3)