Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <termios.h>
- #define MODEM_DEVICE "/dev/ttyUSB0"
- void sendATCommand(int serial_port, const char* command, char* response, int response_size) {
- write(serial_port, command, strlen(command));
- usleep(100000);
- int num_bytes = read(serial_port, response, response_size - 1);
- response[num_bytes] = '\0';
- }
- int main() {
- int serial_port = open(MODEM_DEVICE, O_RDWR);
- if (serial_port < 0) {
- perror("[-] Failed to open modem");
- return 1;
- }
- struct termios tty;
- tcgetattr(serial_port, &tty);
- cfsetispeed(&tty, B115200);
- cfsetospeed(&tty, B115200);
- tty.c_cflag |= (CLOCAL | CREAD);
- tcsetattr(serial_port, TCSANOW, &tty);
- char response[256];
- sendATCommand(serial_port, "AT+CCID\r\n", response, sizeof(response));
- printf("[+] SIM ICCID: %s\n", response);
- sendATCommand(serial_port, "AT+CIMI\r\n", response, sizeof(response));
- printf("[+] IMSI: %s\n", response);
- close(serial_port);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement