Search This Blog

Monday, November 02, 2020

Python substitute for netcat

When working across multiple platforms and flavours of IX, a system administrator  might not always have tools like telnet or netcat available to test network connections. One tool that is on all flavours of IX and is universal is python.


A quick python script for testing network connection.

I used this python script to send a message via UDP to a logstash server.


import socket
message = 'Flah blah bleh'
byteToSend = str.encode(message)
serverAddressPort = ('IP Address', port)
bufferSize = 1024
soc = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
soc.sendto(byteToSend, serverAddressPort)



Tuesday, August 11, 2020

Password validator

 Validating password with python.


Regex

import re

passRX = re.compile(r'[A-Za-z0-9@#$%^&+=]{8,}')

pp = passRX.search('dy_5mupV')

pp == None

True


pp = passRX.search('DEVGukvk')

pp == None

False


Reference:

Thursday, June 18, 2020

awk multiple field separators.

Using multiple field separators with awk and perl to convert "," to a newline.

Example:

echo "100(txt),528(smbw),529(smbt),530(smbn),10115(smbs)"|\
 perl -pe 's/,/\n/g'
100(txt)
528(smbw)
529(smbt)
530(smbn)
10115(smbs)

Using awk to just print the text between ().
echo "100(txt),528(smbw),529(smbt),530(smbn),10115(smbs)"|\
 perl -pe 's/,/\n/g'|\
 awk -F"[()]" '/smb/{print $2}'
smbw
smbt
smbn
smbs

Using awk to just print the text between [].

awk -F'[][]' and awk -F'[[]]' will not work.