#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc,char *argv[],char *env[])
{
int i = 1;
int cfd;
int ret;
struct sockaddr_in server;
if(cfd < 0)
{
perror("socket");
exit(0);
}
bzero(&server,sizeof(server));
server.sin_family = AF_INET;
while(i < 65536)
{
cfd = socket(AF_INET,SOCK_STREAM,0);
server.sin_port = htons(i);
ret = connect(cfd,(void *)&server,sizeof(server));
if(ret == 0)
{
printf("%5d port is open in !/n",i);
}
i++;
close(cfd);
}
close(cfd);
return 0;
}