Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Monday, July 4, 2022

Bash: shell script to obtain the cipher list of a server


#!/bin/bash
 
SERVER=$1
 
if [[ "$SERVER" == "" ]]; then
  echo "Usage: $0 hostname:port"
  exit
fi
 
DELAY=2
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
 
for cipher in ${ciphers[@]}
do
  echo -n Testing $cipher ...
  result=$(echo -n | openssl s_client -cipher "$cipher" -connect $SERVER 2>&1)
 
  if [[ "$result" =~ "Session-ID:" ]]; then
    echo "YES"
  else
    if [[ "$result" =~ ":error:" ]]; then
      error=$(echo -n $result | cut -d':' -f6)
      echo "NO \($error\)"
    elif [[ "$result" =~ "errno=104" ]]; then
      echo "NO \(Connection reset by peer\)"
    else
      echo "Unknown response"
    fi
  fi
 
  sleep $DELAY
done
 

Wednesday, January 29, 2020

Powershell Script: Write to a file


1. Append a string to the end of a file

Add-Content -Path .\theFile -Value "the string to be appended"


2. Append file_a to the end of file_b

Get-Content -Path .\file_a | Add-Content -Path .\file_b


3. Create a new file with a sting as the content

"the string to be put into the file" | Out-File -FilePath .\theFile


Tuesday, January 28, 2020

Powershell Script: Read input with default value


$defaultVal = 'No'

$inputVal = Read-Host -Prompt "Input something? [$defaultVal]"

if ($inputVal -eq '')
{
  $inputVal = $defaultVal
}


 
Get This <