Advertisement
syst3m_h4x0r

Port Listening Script C

Oct 26th, 2017
8,642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. #include <unistd.h>
  7. #include <error.h>
  8. #include <string.h>
  9.  
  10. using namespace std;
  11. struct sockaddr_in dest;
  12.  
  13. /** SH
  14. Script para abrir uma porta
  15. **/
  16.  
  17. void scan(){
  18. int msocket, con, port;
  19. cout << "Entre com o número da porta: ";
  20. cin >> port;
  21.  
  22. if((msocket = socket(AF_INET, SOCK_STREAM, 0)) == -1){
  23. perror("socket");
  24. exit(1);
  25. }
  26. dest.sin_family = AF_INET;
  27. dest.sin_port = htons(port);
  28. bzero(dest.sin_zero, sizeof(dest.sin_zero));
  29.  
  30. if((con = connect(msocket, (struct sockaddr *)&dest, sizeof(dest))) == -1){
  31. perror("connect");
  32. close(msocket);
  33. exit(1);
  34. }else{
  35. cout << "Porta aberta: " << port;
  36. exit(1);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement