zu verlinkende lib: ws2_32.lib
unter Dev-Cpp: libws2_32.a
#include <windows.h> #include <winsock2.h> #include <stdio.h> int start() { WSADATA wsa; return WSAStartup(MAKEWORD(2,0),&wsa); } int main(int argc,char *argv[]) { if(argc!=2) { printf("Benutzung: %s <ip>\n",argv[1]); return 1; } start(); int i; int count=0;; SOCKADDR_IN addr; SOCKET s; long rc; for(i=1;i<65535;i++) { FILE *fp; fp = fopen("log.txt" , "a"); if(i==1) { fprintf(fp,"PORTSCAN ON %s\n",argv[1]); } s = socket(AF_INET,SOCK_STREAM,0); if(s == SOCKET_ERROR) { printf("ERROR: %d\n",s); return 1; } addr.sin_addr.s_addr = inet_addr(argv[1]); addr.sin_port = htons(i); addr.sin_family = AF_INET; rc = connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN)); if(rc!=-1) { printf("OPEN PORT: %d\n",i); fprintf(fp,"OPEN PORT: %d\n",i); count++; } close(s); fclose(fp); } FILE *fp; fp = fopen("log.txt" , "a"); fprintf(fp,"\n%d PORTS OPEN ON %s\n",count,argv[1]); fclose(fp); return 0; }