知道对方机器的IP地址,如何可以判断对方是否开了某个端口,如888端口???(100分)

  • 主题发起人 主题发起人 M16
  • 开始时间 开始时间
M

M16

Unregistered / Unconfirmed
GUEST, unregistred user!
如题!!!
 
尝试用SOCKET与该端口连接,如果连接上,则表示开放,很简单的
 
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<winsock2.h>
#include<ctype.h>
#include<windows.h>


char szAddress[128];
int iStartPort,
iEndPort;

void usage();
void validateArgs(int , char **);

//...........................................................................main() FUNC of ragnascan
int main(int argc, char **argv)
{
WSADATA wsadata;
SOCKET sScan;
struct hostent *host;
struct sockaddr_in suffer;
int iPort,
xPort,
returnValue;

validateArgs(argc, argv);

printf("Target IP is %s Ports strat at %d End at %d/nNow Scanning ....../n",
szAddress,iStartPort,iEndPort); //-------debug_10
for (iPort = iStartPort; iPort <=iEndPort; iPort++)
{
xPort = iPort;

if ((WSAStartup (MAKEWORD(2,2), &amp;wsadata)) != 0)
{
printf("winsock load ERROR!/n");
return 1;
}
//printf("winsock loaded succeed!/n"); //-------debug_20

if ((sScan = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)
{
printf("Creat socket ERROR! ERROR NO.:/n",WSAGetLastError());
return 1;
}
//printf("Creat socket succeed!/n"); //-------debug_30

suffer.sin_family = AF_INET;
suffer.sin_port  = htons(xPort);
suffer.sin_addr.s_addr = inet_addr(szAddress);
if (suffer.sin_addr.s_addr = INADDR_NONE)
{
host = gethostbyname(szAddress);
if (host == NULL)
{
printf("unable resolve host: %s ",szAddress);
return 1;
}
CopyMemory(&amp;suffer.sin_addr, host->h_addr_list[0], host->h_length );

if ((returnValue = (connect(sScan, (struct sockaddr *)&amp;suffer, sizeof (suffer)))) == 0)
{
printf("Port %d open/n",xPort);
}

WSACleanup();
closesocket(sScan);

      shutdown(sScan,SD_BOTH);

}

}
printf("finished the scan! press ANY key to quit/n");
getch();

return (0);
}




//...........................................................................all of SUB FUNCTIONS
//...........................................................................usage() func of ragnascan
void usage()
{
printf("===============================================================================/n");
printf("This is a scanner which named RAGNASCAN. It is only a test for WinsockAPI !/n");
printf("It's my first scanner.If you have any question,mailto: picobsd@163.net/n");

printf("                                kaoru fujiwara/n");
printf("-------------------------------------------------------------------------------/n/n");
printf("USAGE: kscan [-a:IP] [-s:X] [-e:Y]/n");
printf("       -a:IP Target IP Address/n");
printf("       -s:X Port start at No. X/n");
printf("       -s:X Port End  at No. Y/n");

exit(0);
}

//...........................................................................validateArgs() func
void validateArgs(int argc, char **argv)
{
int i;
if (argc < 4)
usage();
for (i=1; i<argc; i++)
{
if (((argv[0] == '/')||(argv[0] == '-'))&amp;&amp;(argv[2] == ':'))
{
switch (tolower(argv[1]))
{
case 'a':
if (strlen(argv) > 3)
strcpy(szAddress, &amp;argv[3]);
break;

case 's':
iStartPort = atoi (&amp;argv[3]);
if ((iStartPort > 65355)||(iStartPort < 1))
{
printf("the Ports that you assigned must between 1-65355!!/n ");
exit (0);
}
break;
case 'e':
iEndPort = atoi (&amp;argv[3]);
if ((iEndPort > 65355)||(iEndPort < 1))
{
printf("the Ports that you assigned must between 1-65355!!/n ");
exit (0);
}
break;
default:
usage();
break;
}

}
else
usage();

}

if (iStartPort > iEndPort)
{
printf("start at %d,end at %d, this porg only accept ASCEND sequence/n",iStartPort,iEndPort);
usage();
}
}
 
大概意思我明白了,有没有什么dos命令可以看本机打开了哪些端口???
 
那有没有命令可以看对方开了哪些端口???
 
另外都有哪些比较常用的DOS命令关于网络方面的,给各简单的列表,除了(ping,netstat,tractrt)
 
后退
顶部