-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhostname_search.go
30 lines (26 loc) · 1.2 KB
/
hostname_search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"database/sql"
)
func hname_search(hostname string, dbtype string, constring string) {
db, err := sql.Open(dbtype, constring)
defer db.Close()
results, err := db.Query("SELECT INET_NTOA(ipv4_address), HEX(dhcp_identifier), dhcp4_subnet_id, hostname FROM hosts where hostname like ?", hostname)
for results.Next() {
rows++
var tag kea_entry
err = results.Scan(&tag.ipntoa, &tag.dehexmac, &tag.hname, &tag.dhcp_id)
if err != nil {
panic(err.Error())
}
fmt.Println("----------------------------------------------------------------")
fmt.Println("|",tag.ipntoa,"|",tag.dehexmac,"|", tag.hname,"|",tag.dhcp_id,"|")
fmt.Println("----------------------------------------------------------------")
if (debug) {
fmt.Println("Rows returned: ", rows)
}
}
db.Close()
}