What you have looks like it will read the first 8 bytes of a file and interpret it as a float64. Based on your screenshot, it looks like you actually want the data at offset 14 (if I’m counting the dots correctly on my phone screen right now). Before you call binary.Read, you should call f.Seek to set the position of the file to the offset of the beginning of the data you want to read, and then call binary.Read.
You’ll need to do the same seeking for the strings you want, too, but you won’t need binary.Read, you could just slice the bytes that you read and then convert to a string after. Are the strings always the same length or do you need to inspect the file at some other offset to determine the string’s length?
I’m not sure what you’re going for with strings.ReplaceAll(string(_ip[:]), " ", " "): This replaces all the spaces with spaces, so essentially a no-op.
My guess, from looking at the file dump, is that they are C strings. Therefore, it’s an attempt to replace NUL by space.
A better solution would be a CToGoString function:
package main
import "fmt"
func CToGoString(c []byte) string {
n := -1
for i, b := range c {
if b == 0 {
break
}
n = i
}
return string(c[:n+1])
}
func main() {
// IPV4
c := []byte("\x34\x31\x2E\x31\x39\x31\x2E\x39\x37\x2E\x36\x32\x00\x00\x00")
fmt.Printf("%d %q\n", len(c), c)
g := CToGoString(c)
fmt.Printf("%d %q\n", len(g), g)
c = []byte("1.1.1.1\x00\x00\x00\x00\x00\x00\x00\x00")
fmt.Printf("%d %q\n", len(c), c)
g = CToGoString(c)
fmt.Printf("%d %q\n", len(g), g)
c = []byte("111.111.111.111")
fmt.Printf("%d %q\n", len(c), c)
g = CToGoString(c)
fmt.Printf("%d %q\n", len(g), g)
c = make([]byte, 15)
fmt.Printf("%d %q\n", len(c), c)
g = CToGoString(c)
fmt.Printf("%d %q\n", len(g), g)
}