Domanda

I need advise to create a simple port-scanner, who will need to detect if some specific devices are connected to the network from their IP/MAC address.

I am working on windows 7 and can use preferably C++ Builder 2010, or java or Qt.

The library have to be under a public domain or equivalent, as my software is a proprietary software.

What library would you advice? Do you know any free software that I could start from, or any examples?

What about using Indy Sockets or Synapse TCP/IP Libraries?

È stato utile?

Soluzione

Any TCP/IP library will work. Indy, ICS, Synapse, they all will work just fine with C++Builder. Since Indy ships with C++Builder, you could start with that, but you are certainly not limited to it.

They all use WinSock internally on Windows, so you could just program to the WinSock API directly and not use any libraries at all. All you would need to do is call WSAStartup() once at program startup, then call socket() and connect() for each port you want to check. To check multiple ports, you can either put the sockets into non-blocking mode with ioctlsocket() and then use either select(), WSAAsyncSelect(), WSAAsyncEvent(), or CreateIoCompletionPort()/GetQueuedCompletionStatus() to detect whether connect() succeeds/fails, or you can put the sockets into blocking mode (their default mode) and use worker threads to call connect() and let it tell you directly if it succeeds/fails.

Altri suggerimenti

An open port is a port which has a listening application on it. Simplest way to check a TCP port is trying to connect it and if the connection established then that port is open.

Advanced methods are based on fingerprinting and prob packets, you can read how nmap detects open ports.

Finally, pcap is a useful library for advanced network programming.

For Borland C++ builder? Sorry, not much out there for Borland C++ builder, but if you could use Visual C++ Express and the WINSOCK library then it is as simple as this :

Winsock portscanner :

#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>
#pragma comment(lib,"WSOCK32.LIB")

void main()
{
   WSADATA data;
   SOCKET sock;
   int err,i,startport,endport;
   char ip[20];
   struct sockaddr_in sock_addr;
   FILE*fp1;

   printf("ip: ");
   scanf("\n%s",ip);
   printf("start port: ");
   scanf("%d",&startport);
   printf("end port: ");
   scanf("%d",&endport);
   if((WSAStartup(MAKEWORD(2,0),&data)!=0))
   {
      printf("Error: Winsock did not init!!!\n\n");
   }
   else
   {
      for(i=startport;i<endport;i++)
      {
         sock=socket(AF_INET,SOCK_STREAM,0);
         sock_addr.sin_family=PF_INET;
         sock_addr.sin_port=htons(i);
         sock_addr.sin_addr.s_addr=inet_addr(ip);
         printf("Checking port %d\n",i);
         err=connect(sock,(struct sockaddr*)&sock_addr,sizeof(struct sockaddr));
         if(err==0)
         {
            printf("Port Open!!!\n\n\a");
            fp1=fopen("ports.txt","a+");
            fprintf(fp1,"Port is open: %d\n\n",i);
            closesocket(sock);
            fclose(fp1);
         }
         else
         {
            printf("Port Closed!!!\n\n");
         }
      }
      WSACleanup();
      system("ports.txt");
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top