func main() { flag.Parse() f, err := os.Open(file) if err != nil { fmt.Printf("打开日志[%s]出错: %s\n", file, err.Error()) return } if err = ip17mon.Init(path); err != nil { fmt.Printf("初始化 ip 库失败: %s\n", err.Error()) return } buf, output := bufio.NewReader(f), make([]string, 0, batch) for { ip, err := buf.ReadString('\n') if err != nil { if err != io.EOF { fmt.Printf("读取日志[%s]出错: %s\n", file, err.Error()) return } break } ip = strings.TrimSpace(ip) loc, err := ip17mon.Find(ip) if err != nil { output = append(output, fmt.Sprintf("%s,%s,%s,%s,%s", ip, err.Error(), "", "", "")) continue } output = append(output, fmt.Sprintf("%s,%s,%s,%s,%s", ip, loc.Country, loc.Region, loc.City, loc.Isp)) if len(output) < batch { continue } fmt.Println(strings.Join(output, "\n")) output = output[:0] } if len(output) > 0 { fmt.Println(strings.Join(output, "\n")) } }
func init() { if err := ip17mon.Init(path + "/conf/17monipdb.dat"); err != nil { log.Fatal(err) } // UMgr.loadUsers() Blogger = UMgr.Get("deepzz") // not found account if Blogger == nil { initAccount() } TMgr.loadTopics() // open error mail,email addr : Blogger.Email log.SetEmail(Blogger.Email) ManageData.LoadData() monitor.HookOnExit("flushdata", flushdata) monitor.Startup() go RequestM.Saver() go timer() }
// init ip data func init() { exec_path, _ := exec.LookPath(os.Args[0]) if err := ip17mon.Init(filepath.Dir(exec_path) + "/17monipdb.dat"); err != nil { panic(err) } }
func initIp() { if err := ip17mon.Init("./17monipdb.dat"); err != nil { log.Fatal(err) } }