Monday, January 3, 2022

Script to grep ip and port number from netstat

Below script is to parse output from netstat -tulnp or ipvsadm -Ln. 

#!/bin/bash

input=$1

vipNportRe="TCP ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{2,3}).*$"

ipNportRe=".*-> ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{2,3}).*$"

netstatIpNportRe="^tcp .* 0 ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{2,3}).*$"

while read line

do

  if [[ $line =~ $ipNportRe ]]; then

    echo "${BASH_REMATCH[1]}"

  elif [[ $line =~ $netstatIpNportRe ]]; then

    echo "${BASH_REMATCH[1]}"

  fi

done < $input


# Get the lines in a.txt but not in b.txt

grep -F -x -v -f b.txt a.txt

Tuesday, December 28, 2021

Mikrotik Router Configuration

 Configure Web Proxy

 /ip proxy set enabled=yes port=8080 src-address=192.168.88.32

Configure Transparent Web Proxy

/ip firewall nat add chain=dstnat protocol=tcp dst-port=80 action=redirect to-ports=8080

OpenDNS Server Addresses

Our nameservers are always:

  • 208.67.222.222
  • 208.67.220.220
Force dhcp client to get opendns server ip addresses.
/ip dhcp-server network add dns-server=208.67.222.222,208.67.220.220
or 


Wednesday, November 10, 2021

Resolve Git Conflict

 Reference:
https://akshayranganath.github.io/Git-Pull-Handling-Merge-Conflict/


Restore Deleted file/folder

For folder:

export file=my_apache_conf.d

For Individule file:

export file=my_apache_conf.d/conf.d/rules-custom.conf

echo $file

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"