Scripts

  • January 14, 2021

    Password Generator Python Script

    Its always useful to be able to quickly generate a password. This Python script uses a word list to create a random 3 word password with dashes between and then drop it into the clipboard. You could modify it so it doesn’t drop it into the clipboard and just passes the variable to another script. The word list I used (britcaps.txt) can be downloaded from here:¬†British English Word List for Spell Checkers – Curlew Communications¬†but you can use other word lists. You will just need to change the wordfilepath variable at the top of the script. # www.jonathanblench.co.uk # Script to generate a 3 word password and drop it into the clipboard to use # Set path the word file as variable wordfilepath = "britcaps.txt" # Import the random module import random # Function to use clipboard import os def addToClipBoard(text): command = 'echo ' + text.strip() + '| clip' os.system(command) # Open and read the words file and split words fileread1 = open(wordfilepath, "r") allcontent = (fileread1.read()) words = list(map(str, allcontent.split())) # Generate 3 random words and store as variables word1 = (random.choice(words)) word2 = (random.choice(words)) word3 = (random.choice(words)) # Bring words together into string and add dashes between words password = word1+"-"+word2+"-"+word3 # Place password into clipboard and display addToClipBoard(password) # Remove hash from next line to print the password. #print (password) Hope you find this useful.
  • There have been many times when I have been investigating a server or device dropping and then coming back online. Here is a useful PowerShell script that updates a txt file each time a device drops. <# Script to log drop in connectivity Checks every 10 seconds. If a drop is detected it checks every 60 seconds until it comes back online. #> #Variables #Set the IP or Hostname you want to test $target = "8.8.8.8" #Set the location of the log file $logfile = "C:\result.txt" #set how often to check connectivity (in seconds) $checktime = 10 #set how long before chacking after a drop in connectivity (in seconds) $rechecktime = 60 #no changes required past here function Test-Ping { param($ip) trap {$false; continue} $timeout = 1000 $object = New-Object system.Net.NetworkInformation.Ping (($object.Send($ip, $timeout)).Status -eq 'Success') } $killswitch=1 Write-Host "Running a network test. **PLEASE DO NOT CLOSE THIS WINDOW**" -Fo Red while ($killswitch -ne 0) { If (!(Test-Ping $target)) { Write-output 'No connection at: ' $(Get-Date -format "dd-MM-yyyy @ hh:mm:ss") | out-file -append $logfile -force Start-Sleep $rechecktime } Else { Start-Sleep $checktime } } Hope you find this useful.