PYTHON CHROOT AND EXIT CHROOT
I know this has been written a few time online, but the last time I needed to read up on it, it took a little long to find the answer.
What I wanted to do was to chroot in to a new root, then exit that chroot via python .
Below we have my current working directory that is /root , take a look at what we have in the directory:
In [1]: import os
In [2]: os.system('pwd')
/root
Out[2]: 0
In [3]: os.system('ls -l /root')
total 12
drwxr-xr-x 3 root root 4096 Dec 5 15:47 filesystems
drwxr-xr-x 3 root root 4096 Dec 5 15:01 iso
drwxr-xr-x 3 root root 4096 Dec 5 15:14 squashfs
Out[3]: 0
I’m then going to keep track of my current root, this part is very important:
GET INTERFACE GOLANG PART 2
Wanted to share a few updates and tweaks to the original Get Interface name by hardware address code. The below is broken up in to functions to help with code re-useability .
If also prints all interface names and hardware address when no command line argument are present.
package main
import (
"net"
"fmt"
"os"
"strings"
)
// Use the net library to return all Interfaces
// and capture any errors.
func getInterfaces() ([]net.Interface) {
interfaces, err := net.Interfaces()
if err != nil {
panic("Unable to get interfaces.")
}
return interfaces
}
// Use the net library to get Interface by Index number
// and capture any errors.
func getInterfaceByIndex(index int) (*net.Interface) {
inter, err := net.InterfaceByIndex(index)
if err != nil {
panic("Unable to get interface by index")
}
return inter
}
// Use the net library to get Interface by Name
// and capture any errors
func getInterfaceByName(name string) (*net.Interface) {
inter, err := net.InterfaceByName(name)
if err != nil {
panic("Unable to get interface by name")
}
return inter
}
// Using the net library we will loop over all interfaces
// looking for the interface with matching mac_address.
func getInterfaceByHardwareAddress(mac string) (net.Interface) {
interfaces := getInterfaces()
for _, inter := range interfaces {
if strings.ToUpper(mac) == strings.ToUpper(inter.HardwareAddr.String()) {
return inter
}
}
panic("Unable to find interface with Hardware Address.")
}
func main() {
args := os.Args
// If we have only 2 arguments we will assume the
// second is mac_address.
if len(args) == 2 {
mac_address := args[1]
inter := getInterfaceByHardwareAddress(mac_address)
fmt.Println(inter.Name)
// If no arguments were passed in lets just return
// a list of all interface names and hardware addresses.
} else if len(args) == 1 {
for _, inter := range getInterfaces() {
fmt.Println(inter.Name, inter.HardwareAddr)
}
// If the number of command line arguments are not expected
// lets panic and explain why.
} else {
panic("We require one (mac_address) or no command line arguments.")
}
}
Usage looks something like this:
GET INTERFACE NAME BY HARDWARE ADDRESS
At work we have had a need for getting a interface name by mac address and are in a environment that doesn’t have many common Linux tools (nor would I want to regex it as the environment will constantly be changing).
My first solution was to to write a C program (about 125 lines) which used the linux/rtnetlink library. However, now that I’m looking at Golang I figured why not rewrite this (which is only about 40 lines).
GEEK OR NERD?
So the other day two of my book arrived in the mail.
The Go Programming book was so cheap I couldn’t say no (only $9.00), and the Pathfinder Players Guide offered new classes which my kids wanted to check out.
So here is the question, does this make me a Nerd or a Geek ?
ZOMBIE DICE
Was able to pull out a victory last night against my two boys in Zombie Dice with some help from a little Homebrew.
If you don’t know what Zombie Dice is, you should have a look at the Tabletop Video.
It is a very inexpensive travel sized gamed, which is easy for younger players, and very exciting!
PAINTING MINIATURES
Did some miniature painting over the weekend with my eldest son.
I really like the kobold army with leader.
PATHFINDER DICE ARENA SETUP
We are getting ready to test out the new Pathfinder Dice Arena game, check out the setup.