Advertisement
sighting

Proxy Checker

Jan 1st, 2019
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. // Proxy Checker By Netflooding
  2. // Format: IP PORT
  3. // Usage: cat proxies.txt | ./checker 2
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netdb.h>
  10. #include <unistd.h>
  11. #include <fcntl.h>
  12. #include <errno.h>
  13. #include <signal.h>
  14. #include <ctype.h>
  15. #include <arpa/inet.h>
  16.  
  17. int Timeout;
  18. #define ERROR "[\x1b[31m?\x1b[37m]"
  19. #define FAILED "[\x1b[31m-\x1b[37m]"
  20. #define SUCCESS "[\x1b[32m+\x1b[37m]"
  21.  
  22. void Trim(char *str)
  23. {
  24. int i;
  25. int begin = 0;
  26. int end = strlen(str) - 1;
  27. while (isspace(str[begin])) begin++;
  28. while ((end >= begin) && isspace(str[end])) end--;
  29. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  30. str[i - begin] = '\0';
  31. }
  32.  
  33. void proxy(char *host, int port, char *output_file)
  34. {
  35. int fd = -1;
  36. struct timeval timeout;
  37. struct sockaddr_in fds;
  38. timeout.tv_sec = Timeout;
  39. timeout.tv_usec = 0;
  40. fd = socket(AF_INET, SOCK_STREAM, 0);
  41. setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  42. setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
  43. fds.sin_family = AF_INET;
  44. fds.sin_port = htons(port);
  45. fds.sin_addr.s_addr = inet_addr(host);
  46. if(connect(fd, (struct sockaddr *)&fds, sizeof(fds)) == -1)
  47. {
  48. // failed 2 connect
  49. printf(FAILED" %s:%d Timeout...\n", host, port);
  50. goto end;
  51. }
  52. else
  53. {
  54. // successful connection
  55. printf(SUCCESS" Connected to proxy [%s:%d]\n", host, port);
  56. char cmd[45];
  57. snprintf(cmd, sizeof(cmd), "echo '%s %d' >> %s", host, port, output_file);
  58. system(cmd);
  59. goto end;
  60. }
  61. end:
  62. close(fd);
  63. return;
  64. }
  65.  
  66. int main(int argc, char **argv)
  67. {
  68. char buffer[513];
  69. if(argc < 3 || argc > 3)
  70. {
  71. printf(ERROR" Usage: cat proxies.txt | %s <timeout> <outfile>\n", argv[0]);
  72. exit(0);
  73. }
  74. Timeout = atoi(argv[1]);
  75. while(fgets(buffer, sizeof(buffer) - 1, stdin))
  76. {
  77. if(strlen(buffer) < 3 || buffer == NULL)
  78. break;
  79. Trim(buffer);
  80. char *Host = strtok(buffer, " ");
  81. int port = atoi(Host+strlen(Host)+1);
  82. //printf("Host: %s\nPort: %d\n", Host, port);
  83. if(!(fork()))
  84. {
  85. proxy(Host, port, argv[2]);
  86. exit(0);
  87. }
  88. }
  89. return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement