Skip to content
Snippets Groups Projects
Commit fe82c878 authored by Bashar Al-Saify's avatar Bashar Al-Saify
Browse files

del

parent d445c134
No related branches found
No related tags found
No related merge requests found
File deleted
// Import JSDOM
const { JSDOM } = require('jsdom');
// Function to count expired and not expired certificates
async function countExpiredAndNotExpired(domain) {
try {
// Construct the URL for crt.sh search
const url = `https://crt.sh/?q=${domain}`;
// Fetch the HTML content of the search results page
const response = await fetch(url);
const html = await response.text();
// Create a new JSDOM instance
const dom = new JSDOM(html);
// Get the document object from JSDOM
const doc = dom.window.document;
// Find all certificate rows in the table
const certificateRows = doc.querySelectorAll('table tr');
// Initialize counters for expired and not expired certificates
let expiredCount = 0;
let notExpiredCount = 0;
// Iterate over each certificate row
certificateRows.forEach(row => {
// Extract "Not Before" and "Not After" dates from the row
const notBeforeCell = row.querySelector('td:nth-child(3)');
const notAfterCell = row.querySelector('td:nth-child(4)');
// Check if both cells are found
if (notBeforeCell && notAfterCell) {
const notBeforeText = notBeforeCell.textContent.trim();
const notAfterText = notAfterCell.textContent.trim();
// Convert date strings to Date objects
const notBefore = new Date(notBeforeText);
const notAfter = new Date(notAfterText);
// Check if the certificate is expired
if (notAfter < new Date()) {
expiredCount++;
} else {
notExpiredCount++;
}
}
});
// Return the counts of expired and not expired certificates
return { expiredCount, notExpiredCount };
} catch (error) {
console.error('An error occurred:', error);
return null;
}
}
// Extract domain from command-line arguments
const domain = process.argv[2];
// Check if the domain name is provided
if (!domain) {
console.error('Please provide a domain name as an argument.');
process.exit(1); // Exit with a non-zero status code to indicate an error
}
// Example usage: Count expired and not expired certificates for a domain
countExpiredAndNotExpired(domain)
.then(result => {
if (result) {
console.log(`Expired certificates: ${result.expiredCount}`);
console.log(`Not expired certificates: ${result.notExpiredCount}`);
} else {
console.log('Failed to retrieve certificate information.');
}
})
.catch(error => console.error('An error occurred:', error));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment