Golang – Check if IPv4 is valid and resolve FQDN

This recipe demonstrates if string is a valid IPv4, and also to resolve a FQDN to IP address. This recipe uses os.Args to get the second argument as FQDN and call net.ResolveIPAddr() function to do a FQDN resolution to IP address. package main import ( "fmt" "log" "net" "os" ) func isIPv4Addr(ip string) bool { … Continue reading Golang – Check if IPv4 is valid and resolve FQDN

Golang – Write sentence to file

This recipe demonstrates how to use flag to build a command line program, how to convert string slice to string and how to write sentence to file specified by user. Usage example: writefile -f test.txt hi this is a test. package main import ( "flag" "io" "log" "os" "strings" ) func convertSliceToString(s []string) string { … Continue reading Golang – Write sentence to file

Golang – Obfuscate password input

This recipe shows how to obfuscate the password when user is typing the password. package p1 import ( "fmt" "log" "os" "golang.org/x/crypto/ssh/terminal" ) func getPassword() string { fmt.Println("\nPassword: ") // https://godoc.org/golang.org/x/crypto/ssh/terminal#ReadPassword // terminal.ReadPassword accepts file descriptor as argument, returns byte slice and error. passwd, e := terminal.ReadPassword(int(os.Stdin.Fd())) if e != nil { log.Fatal(e) } // … Continue reading Golang – Obfuscate password input

Golang – How to write ssh.HostKeyCallback

ssh.InsecureIgnoreHostKey is lazy and seems popular? I have seen many tutorials and some codes in github that ignore host key checking, this is not recommended as you need to ensure everytime you connect to the known ssh server is the actual server that serves your purpose, if host key checking is ignore then any server … Continue reading Golang – How to write ssh.HostKeyCallback

[python]Creating vlans on multiple switches

Introduction The entire script demo can be found here. The script reads from an excel sheet named as "vlans.xlsx" and extracts the information, the information is then converted into vlan commands with a jinja2 template, the script is able to send to multiple switches by using threading, on each thread a new Switch instance is … Continue reading [python]Creating vlans on multiple switches