|
@@ -14,37 +14,49 @@ const (
|
|
TargetCountry
|
|
TargetCountry
|
|
TargetRegionGroup
|
|
TargetRegionGroup
|
|
TargetRegion
|
|
TargetRegion
|
|
|
|
+ TargetASN
|
|
|
|
+ TargetIP
|
|
)
|
|
)
|
|
|
|
|
|
func (t TargetOptions) GetTargets(ip net.IP) ([]string, int) {
|
|
func (t TargetOptions) GetTargets(ip net.IP) ([]string, int) {
|
|
|
|
|
|
targets := make([]string, 0)
|
|
targets := make([]string, 0)
|
|
|
|
|
|
- var country, continent string
|
|
|
|
|
|
+ var country, continent, region, regionGroup, asn string
|
|
var netmask int
|
|
var netmask int
|
|
|
|
|
|
- switch {
|
|
|
|
- case t >= TargetRegionGroup:
|
|
|
|
- var region, regionGroup string
|
|
|
|
|
|
+ if t&TargetASN > 0 {
|
|
|
|
+ asn, netmask = geoIP.GetASN(ip)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if t&TargetRegion > 0 || t&TargetRegionGroup > 0 {
|
|
country, continent, regionGroup, region, netmask = geoIP.GetCountryRegion(ip)
|
|
country, continent, regionGroup, region, netmask = geoIP.GetCountryRegion(ip)
|
|
- if t&TargetRegion > 0 && len(region) > 0 {
|
|
|
|
- targets = append(targets, region)
|
|
|
|
- }
|
|
|
|
- if t&TargetRegionGroup > 0 && len(regionGroup) > 0 {
|
|
|
|
- targets = append(targets, regionGroup)
|
|
|
|
- }
|
|
|
|
|
|
|
|
- case t >= TargetContinent:
|
|
|
|
|
|
+ }else if t&TargetCountry > 0 || t&TargetContinent > 0 {
|
|
country, continent, netmask = geoIP.GetCountry(ip)
|
|
country, continent, netmask = geoIP.GetCountry(ip)
|
|
}
|
|
}
|
|
|
|
|
|
- if len(country) > 0 {
|
|
|
|
- if t&TargetCountry > 0 {
|
|
|
|
- targets = append(targets, country)
|
|
|
|
- }
|
|
|
|
- if t&TargetContinent > 0 && len(continent) > 0 {
|
|
|
|
- targets = append(targets, continent)
|
|
|
|
- }
|
|
|
|
|
|
+ if t&TargetIP > 0 {
|
|
|
|
+ targets = append(targets, ip.String())
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if t&TargetASN > 0 && len(asn) > 0 {
|
|
|
|
+ targets = append(targets, asn)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if t&TargetRegion > 0 && len(region) > 0 {
|
|
|
|
+ targets = append(targets, region)
|
|
|
|
+ }
|
|
|
|
+ if t&TargetRegionGroup > 0 && len(regionGroup) > 0 {
|
|
|
|
+ targets = append(targets, regionGroup)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if t&TargetCountry > 0 && len(country) > 0 {
|
|
|
|
+ targets = append(targets, country)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if t&TargetContinent > 0 && len(continent) > 0 {
|
|
|
|
+ targets = append(targets, continent)
|
|
}
|
|
}
|
|
|
|
|
|
if t&TargetGlobal > 0 {
|
|
if t&TargetGlobal > 0 {
|
|
@@ -70,6 +82,12 @@ func (t TargetOptions) String() string {
|
|
if t&TargetRegion > 0 {
|
|
if t&TargetRegion > 0 {
|
|
targets = append(targets, "region")
|
|
targets = append(targets, "region")
|
|
}
|
|
}
|
|
|
|
+ if t&TargetASN > 0 {
|
|
|
|
+ targets = append(targets, "asn")
|
|
|
|
+ }
|
|
|
|
+ if t&TargetIP > 0 {
|
|
|
|
+ targets = append(targets, "ip")
|
|
|
|
+ }
|
|
return strings.Join(targets, " ")
|
|
return strings.Join(targets, " ")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -88,6 +106,10 @@ func parseTargets(v string) (tgt TargetOptions, err error) {
|
|
x = TargetRegionGroup
|
|
x = TargetRegionGroup
|
|
case "region":
|
|
case "region":
|
|
x = TargetRegion
|
|
x = TargetRegion
|
|
|
|
+ case "asn":
|
|
|
|
+ x = TargetASN
|
|
|
|
+ case "ip":
|
|
|
|
+ x = TargetIP
|
|
default:
|
|
default:
|
|
err = fmt.Errorf("Unknown targeting option '%s'", t)
|
|
err = fmt.Errorf("Unknown targeting option '%s'", t)
|
|
}
|
|
}
|