-
scanning a network
I made a little socket serverthat works (tested with telnet) and now I am starting to code myself a client to interact with the server.
The problem:
multiple pc can host multiple servers with diffirent ports. The client will have to scan the network to search for servers and build a list of server where one is choosen at random.
Now scanning the network (10.0.0.1 - 10.0.0.254) takes forever.
Code:
for(i = 1 ; i < 255 ; i++){
bzero(address,16);
sprintf(address,"%s%d",NETWORK,i);
serv_addr.sin_addr.s_addr = inet_addr(address);
for (y = MINPORT ; y <= MAXPORT ;y++){
serv_addr.sin_port = htons(y);
if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(struct sockaddr)) < 0){
if (DEBUG){printf("%s:%d no connection\n",address,y);}/*No server found*/
}
else{
found++;
if (DEBUG){printf("w0000000000t %s:%d got connection\n",address,y);}
close(sockfd);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
}
}
}
}
There has to be a better way to do this I hope. Please help.
-
it would be best to use raw sockets and send the connection attempt manually. The connect function can take forever to timeout. This isn't an easy thing to do, though there are plenty of open source things for linux that will do this. There is one in particular, but I can't quite remember the name. try doing a google search for something like "raw sockets syn packet"
-
Hi
Nmap is a powerful open source port scanner. I don't know but it may have a network scannig option.
http://www.insecure.org/nmap/
Hope helps...
-
I am now testing the raw sockets thing. Hope it works. Also I think I just might change my server to respond a broadcast and then sending his ip and port to the client that send the broardcast.
Will see if nmap can help.
Ty to you will let you know how it works out