Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Simple port scanner - C Code Bank


Simple port scanner
simple port scanner.
                /*
title	: simple port scanner
author	: r3dwood
note	: include file libws2_32.a (in dev-cpp) before compiling.
*/
#include <windows.h>
#include <stdio.h>

int main()
{
	WSADATA wsa;
	SOCKET sock;
	struct sockaddr_in s;
	int port[]={21,22,23,53,80,110,137,139,443,3306,8080}; // add if you want to.
	int j;
	WSAStartup(MAKEWORD(1,1),&wsa);
	for(j=0;j<=sizeof(port)/sizeof(int);j++)
		{
			sock=socket(AF_INET,SOCK_STREAM,0);
			s.sin_family=AF_INET;
			s.sin_port=htons(port[j]);
			s.sin_addr.s_addr=inet_addr("127.0.0.1");
			if(connect(sock,(SOCKADDR*)&s,sizeof(s))==0)
				{
					printf("Port %d open\r\n",port[j]);
					}
			else
				{
					printf("Port %d close\r\n",port[j]);
					}
			closesocket(sock);
			}
	WSACleanup();
	return 0;
	}

            
Comments
Sorry but there are no comments to display