Jump to content
ANdreicj

[ C++ ] Port Scanner

Recommended Posts

Posted
#include <stdio.h> 
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


int main(int argc, char **argv ){
int sc;
int i;
char IP[100];

printf("Provide IP for scann : ");[color=violet] /* se cere IP-ul care va fi scanat ( de porturi ) , incercati IP-ul de pe computerul local */ [/color]
scanf("%s",&IP);

printf(" n Scanning nn");

for(i=0;i<65535;++i) [color=violet]/* o structura repetitiva , de la 0-65000 , se conecteaza pe rand la fiecare dintre aceste porturi , pentru a le verifica starea : deschis / inchis */ [/color]
{
struct sockaddr_in server;
sc = socket(AF_INET, SOCK_STREAM,0); [color=violet]/* se declara socketul client */[/color]
server.sin_family = AF_INET; [color=violet]/* familia acestuia , aici AF_INET , pentru comunicarea pe Internet : TCP/IP*/[/color]
server.sin_addr.s_addr = inet_addr(IP); [color=violet]/* IP-ul care se doreste a fi scanat , la care se va face conexiunea , pe fiecare port in parte */[/color]
server.sin_port = htons(i);[color=violet] /* portul care va fi scanat , repetitiv de la 0-65000 */[/color]
if( connect(sc, (struct sockaddr *)&server, sizeof(server)) < 0 )
[color=violet]/* ne conectam la fiecare port in parte , [color=red] connect () , acesta returnand o valoare negativa daca nu e deschis si pozitiva daca este */[/color]
{ }
else{
printf(" : Open " ); [color=violet]/* Daca valoarea nu e negativa , portul e deschis si se afiseaza corespunzator */[/color]
printf(" %d : n",i);

}
}
close(sc); [color=violet]/* se inchide socketul client */[/color]
return 0;[color=violet] /* se inchide functia main , returnandu-se 0 */[/color]

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...