Skip to content

Instantly share code, notes, and snippets.

@reginaldosnunes
Created February 11, 2024 23:41
Show Gist options
  • Save reginaldosnunes/fc45eaf4bab2d65e55220a5f378ca0b9 to your computer and use it in GitHub Desktop.
Save reginaldosnunes/fc45eaf4bab2d65e55220a5f378ca0b9 to your computer and use it in GitHub Desktop.
Simple Get Domain Expires Date
<#
.SYNOPSIS
Simple Get Domain Expires Date
.DESCRIPTION
Performs a domain name lookup and returns expiration date
.PARAMETER file
After set -f add a string argument to specifies the file name with a list of domains
.PARAMETER domain
After set -d add a string argument to specifies the domain name, enter the domain name without http:// and www (e.g. google.com))
.PARAMETER arg
string argument with file name or domain name
.EXAMPLE
Get-DomainExpires -d google.com
Get-DomainExpires -f domain-list.txt
.NOTES
File Name: Get-DomainExpires.ps1
Author: Reginaldo Nunes
GitHub: https://github.com/reginaldosnunes
Last Edit: 02/11/2024
#>
param (
[switch]$file,
[switch]$domain,
[string]$arg
)
function Get-ExpireDate($name) {
if ($name -match "\.br$") {
$rdapService = "https://rdap.registro.br/domain";
$eventsIndex = 2;
} else {
$rdapService = "https://rdap.org/domain"
$eventsIndex = 1;
}
$domainRDAPJSON = Invoke-RestMethod -uri "$rdapService/$name"
$domainExpires = $domainRDAPJSON.events[$eventsIndex].eventDate.ToString('dd/MM/yyyy');
return "$name expira em $domainExpires`n";
}
if ($file) {
$filePath = $arg;
$lines = Get-Content $filePath;
for ($i = 0; $i -lt $lines.Count; $i++) {
$line = $lines[$i]
$domainExpireList += Get-ExpireDate $line
}
Write-Output $domainExpireList
} elseif ($domain) {
Get-ExpireDate $arg
} else {
Write-Error "Invalid syntax, use -f domainFileList.txt to check a list of domains or -d domain.com.br to check just one domain."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment