updated ScanIP function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1868bb2ea4
commit
9244e05fc3
@ -37,12 +37,6 @@ func GetIPsLast(ctx *context.Context, config *config.Config, interval string) (a
|
||||
}
|
||||
|
||||
func (ip *IP) GetOrCreate(session *xorm.Session) (apiip *APIIP, err error) {
|
||||
var tmpip = &IP{IP: ip.IP}
|
||||
has, err := session.Get(tmpip)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
ip.City.GetOrCreate(session)
|
||||
ip.Country.GetOrCreate(session)
|
||||
ip.AutonomousSystem.GetOrCreate(session)
|
||||
@ -50,6 +44,16 @@ func (ip *IP) GetOrCreate(session *xorm.Session) (apiip *APIIP, err error) {
|
||||
ip.Src.GetOrCreate(session)
|
||||
session.Commit()
|
||||
|
||||
var tmpip *IP
|
||||
if ip.ID != 0 {
|
||||
tmpip = &IP{ID: ip.ID, IP: ip.IP}
|
||||
} else {
|
||||
tmpip = &IP{IP: ip.IP}
|
||||
}
|
||||
has, err := session.Get(tmpip)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
if !has {
|
||||
session.Insert(ip)
|
||||
} else {
|
||||
@ -129,12 +133,11 @@ func ScanIP(cfg *config.Config) (err error) {
|
||||
for {
|
||||
session := cfg.Db.NewSession()
|
||||
orphans := []IP{}
|
||||
err = session.Where("as_id is null or country_id is null or src_id is null or host_id is null").Asc("updated").Limit(ScanLimit).Find(&orphans)
|
||||
err = session.Where("(as_id is null or country_id is null or city_id is null or rdns = '') and updated < now()-'1d'::interval").Asc("updated").Limit(ScanLimit).Find(&orphans)
|
||||
session.Close()
|
||||
|
||||
if err == nil && len(orphans) > 0 {
|
||||
session := cfg.Db.NewSession()
|
||||
err = session.Begin()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@ -161,17 +164,20 @@ func ScanIP(cfg *config.Config) (err error) {
|
||||
log.Printf("%s -> \"%s\"\n", orphan.IP, query.Rdns)
|
||||
|
||||
orphan.GetOrCreate(session)
|
||||
}
|
||||
|
||||
err = session.Commit()
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
session.Close()
|
||||
err = session.Commit()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
err = session.Close()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
} else {
|
||||
time.Sleep(10 * time.Second)
|
||||
time.Sleep(2 * time.Minute)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user