- #include "unp.h"
- int
- main(int argc, char **argv)
- {
- int sockfd, i;
- struct sockaddr_in servaddr;
- if (argc != 2)
- err_quit("usage: a.out <IPaddress>");
- for(i=1; i<1023; i++)
- {
- if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- err_sys("socket error");
- bzero(&servaddr, sizeof(servaddr));
- servaddr.sin_family = AF_INET;
- servaddr.sin_port = htons(i);
- if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0)
- err_quit("inet_pton error for %s", argv[1]);
- if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) == 0)
- printf("Port %d available.n", i);
- close(sockfd);
- }
- exit(0);
- }
net hw
By: ryan | Date: Oct 10 2006 00:50 | Format: None | Expires: never | Size: 822 B | Hits: 1432
Latest pastes
57 minutes ago
10 hours ago
1 days ago
2 days ago
2 days ago