Advertisement
Sweetening

Untitled

Feb 12th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include <termios.h>
  7.  
  8. #define MODEM_DEVICE "/dev/ttyUSB0"
  9.  
  10. void sendATCommand(int serial_port, const char* command, char* response, int response_size) {
  11. write(serial_port, command, strlen(command));
  12. usleep(100000);
  13. int num_bytes = read(serial_port, response, response_size - 1);
  14. response[num_bytes] = '\0';
  15. }
  16.  
  17. int main() {
  18. int serial_port = open(MODEM_DEVICE, O_RDWR);
  19. if (serial_port < 0) {
  20. perror("[-] Failed to open modem");
  21. return 1;
  22. }
  23.  
  24. struct termios tty;
  25. tcgetattr(serial_port, &tty);
  26. cfsetispeed(&tty, B115200);
  27. cfsetospeed(&tty, B115200);
  28. tty.c_cflag |= (CLOCAL | CREAD);
  29. tcsetattr(serial_port, TCSANOW, &tty);
  30.  
  31. char response[256];
  32.  
  33. sendATCommand(serial_port, "AT+CCID\r\n", response, sizeof(response));
  34. printf("[+] SIM ICCID: %s\n", response);
  35.  
  36. sendATCommand(serial_port, "AT+CIMI\r\n", response, sizeof(response));
  37. printf("[+] IMSI: %s\n", response);
  38.  
  39. close(serial_port);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement