Exemple #1
0
func main() {
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, ' ', 0)
	defer w.Flush()

	flag.Parse()

	u, err := unifi.Login(*user, *pass, *host, *siteid, *version)
	if err != nil {
		log.Fatalln("Login returned error: ", err)
	}
	defer u.Logout()

	aps, err := u.Aps()
	if err != nil {
		log.Fatalln(err)
	}

	for _, s := range aps {
		p := []string{
			s.Name,
			s.IP,
			s.Mac,
			s.ModelName(),
			s.Version,
			s.Status(),
			strconv.Itoa(s.NumSta),
			unifi.Bytes(s.TxBytes).String(),
			unifi.Bytes(s.RxBytes).String(),
		}
		fmt.Fprintln(w, strings.Join(p, "\t"))
	}
}
Exemple #2
0
func main() {
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 3, ' ', 0)
	defer w.Flush()

	flag.Parse()
	u, err := unifi.Login(*user, *pass, *host, *siteid, *version)
	if err != nil {
		log.Fatal("Login returned error: ", err)
	}
	defer u.Logout()

	aps, err := u.ApsMap()
	if err != nil {
		log.Fatal(err)
	}
	sta, err := u.Sta()
	if err != nil {
		log.Fatal(err)
	}

	for _, s := range sta {
		a := aps[s.ApMac]
		p := []string{
			s.Name(),
			s.Radio,
			strconv.Itoa(s.Channel),
			s.EssID,
			strconv.Itoa(s.RoamCount),
			strconv.Itoa(s.Signal),
			strconv.Itoa(s.Noise),
			strconv.Itoa(s.Rssi),
			a.Name,
			s.IP,
			a.ModelName(),
		}
		fmt.Fprintln(w, strings.Join(p, "\t"))
	}
}
Exemple #3
0
func main() {
	flag.Parse()
	u, err := unifi.Login(*user, *pass, *host, *siteid, *version)
	if err != nil {
		log.Fatal(err)
	}

	defer u.Logout()
	apsmap, err := u.ApsMap()
	if err != nil {
		log.Fatal(err)
	}

	elog := log.New(os.Stderr, "", log.Ltime)
	slog, err := syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_DAEMON, 0)
	if err != nil {
		log.Fatal(err)
	}
	logger := []*log.Logger{elog, slog}

	for {
		time.Sleep(*delay)
		newmap := make(roamMap)
		sta, err := u.Sta()
		if err != nil {
			continue
		}
		for _, s := range sta {
			newmap[s.Mac] = roaming{
				Name:    s.Name(),
				IP:      s.IP,
				Ap:      apsmap[s.ApMac].Name,
				Channel: s.Channel,
				Essid:   s.EssID,
			}
		}
		for k, v := range newmap {
			if z, ok := stamap[k]; !ok {
				elog.SetPrefix(" → ")
				for _, l := range logger {
					l.Printf("%s appears on %s/%d %s/%s\n",
						v.Name, v.Ap, v.Channel, v.Essid, v.IP)
				}
			} else if z != v {
				elog.SetPrefix(" ↔ ")
				for _, l := range logger {
					l.Printf("%s roams from %s/%d %s/%s to %s/%d %s/%s\n",
						v.Name,
						z.Ap, z.Channel, z.Essid, z.IP,
						v.Ap, v.Channel, v.Essid, v.IP)
				}
			}
			delete(stamap, k)
		}
		for _, v := range stamap {
			elog.SetPrefix(" ← ")
			for _, l := range logger {
				l.Printf("%s vanishes from %s/%d %s/%s\n",
					v.Name, v.Ap, v.Channel, v.Essid, v.IP)
			}
		}
		stamap = newmap
	}
}