Scan the entire Internet looking for webservers

This revision is from 2024/02/10 06:08. You can Restore it.

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define PORT_80 80
#define PORT_443 443

char *check_port_open(int port, char *ip_address) {
    // ... (same as before)

    if (result == 0) {
        printf("Port %d is open on %sn", port, ip_address);
        return strdup(ip_address);
    } else {
        // ... (same as before)
    }
}

int main() {
    FILE *csv_file = fopen("open_ports.csv", "w");
    if (csv_file == NULL) {
        perror("Failed to open CSV file");
        return 1;
    }

    for (int i = 0; i < 256; ++i) { // Loop for first octet
        for (int j = 0; j < 256; ++j) { // Loop for second octet
            for (int k = 0; k < 256; ++k) { // Loop for third octet
                for (int l = 1; l <= 255; ++l) { // Loop for fourth octet, start from 1 to exclude 0.0.0.0

                    char ip_address[16];
                    snprintf(ip_address, 16, "%d.%d.%d.%d", i, j, k, l);

                    char *open_ip = check_port_open(PORT_80, ip_address);
                    if (open_ip != NULL) {
                        fprintf(csv_file, "%s,%dn", open_ip, PORT_80);
                        free(open_ip);
                    }

                    open_ip = check_port_open(PORT_443, ip_address);
                    if (open_ip != NULL) {
                        fprintf(csv_file, "%s,%dn", open_ip, PORT_443);
                        free(open_ip);
                    }
                }
            }
        }
    }

    fclose(csv_file);
    return 0;
}
{/pre}

  

📝 📜 ⏱️ ⬆️