Skip to content

Commit e752e95

Browse files
committed
Added support for fraud score
1 parent d5f56ab commit e752e95

File tree

7 files changed

+74
-49
lines changed

7 files changed

+74
-49
lines changed

LICENSE.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 - 2024 IP2Location.com
3+
Copyright (c) 2018 - 2025 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# IP2Proxy Go Package
55

6-
This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES), residential proxies (RES), consumer privacy networks (CPN), and enterprise private networks (EPN). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
6+
This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES), residential proxies (RES), consumer privacy networks (CPN), enterprise private networks (EPN) and fraud score. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
77

88
* Free IP2Proxy BIN Data: https://lite.ip2location.com
99
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy

docs/source/code.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Close and clean up the file pointer.
1212
```
1313

1414
```{py:function} PackageVersion()
15-
Return the database's type, 1 to 10 respectively for PX1 to PX11. Please visit https://www.ip2location.com/databases/ip2proxy for details.
15+
Return the database's type, 1 to 12 respectively for PX1 to PX12. Please visit https://www.ip2location.com/databases/ip2proxy for details.
1616
1717
:return: Returns the package version.
1818
:rtype: string
@@ -36,8 +36,8 @@ Return the database's compilation date as a string of the form 'YYYY-MM-DD'.
3636
Retrieve geolocation information for an IP address.
3737
3838
:param string ipAddress: (Required) The IP address (IPv4 or IPv6).
39-
:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array
40-
:rtype: array
39+
:return: Returns the geolocation information in an object. Refer below table for the fields avaliable in the object
40+
:rtype: object
4141
4242
**RETURN FIELDS**
4343
@@ -56,4 +56,5 @@ Retrieve geolocation information for an IP address.
5656
| Threat | Security threat reported. |
5757
| ProxyType | Type of proxy. |
5858
| Provider | Name of VPN provider if available. |
59+
| FraudScore | Potential risk score (0 - 99) associated with IP address. |
5960
```

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# -- Project information
55

66
project = 'IP2Proxy Go'
7-
copyright = '2024, IP2Location'
7+
copyright = '2025, IP2Location'
88
author = 'IP2Location'
99

1010
release = '0.1.0'

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# IP2Proxy Go Package
55

6-
This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES), residential proxies (RES), consumer privacy networks (CPN), and enterprise private networks (EPN). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
6+
This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range, search engine robots (SES), residential proxies (RES), consumer privacy networks (CPN), enterprise private networks (EPN) and fraud score. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
77

88
* Free IP2Proxy BIN Data: <https://lite.ip2location.com>
99
* Commercial IP2Proxy BIN Data: <https://www.ip2location.com/database/ip2proxy>

docs/source/quickstart.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
)
3535

3636
func main() {
37-
db, err := ip2proxy.OpenDB("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN")
37+
db, err := ip2proxy.OpenDB("./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE.BIN")
3838

3939
if err != nil {
4040
return
@@ -65,6 +65,7 @@ func main() {
6565
fmt.Printf("LastSeen: %s\n", all.LastSeen);
6666
fmt.Printf("Threat: %s\n", all.Threat)
6767
fmt.Printf("Provider: %s\n", all.Provider)
68+
fmt.Printf("FraudScore: %s\n", all.FraudScore)
6869

6970
db.Close()
7071
}

ip2proxy.go

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Package ip2proxy allows user to query an IP address if it was being used as
22
// VPN anonymizer, open proxies, web proxies, Tor exits, data center,
3-
// web hosting (DCH) range, search engine robots (SES) and residential (RES)
3+
// web hosting (DCH) range, search engine robots (SES), residential (RES),
4+
// consumer privacy networks (CPN) and enterprise private networks (EPN)
45
// by using the IP2Proxy database.
56
package ip2proxy
67

@@ -61,6 +62,7 @@ type IP2ProxyRecord struct {
6162
LastSeen string
6263
Threat string
6364
Provider string
65+
FraudScore string
6466
IsProxy int8
6567
}
6668

@@ -69,51 +71,54 @@ type DB struct {
6971
f dbReader
7072
meta ip2proxyMeta
7173

72-
countryPositionOffset uint32
73-
regionPositionOffset uint32
74-
cityPositionOffset uint32
75-
ispPositionOffset uint32
76-
proxyTypePositionOffset uint32
77-
domainPositionOffset uint32
78-
usageTypePositionOffset uint32
79-
asnPositionOffset uint32
80-
asPositionOffset uint32
81-
lastSeenPositionOffset uint32
82-
threatPositionOffset uint32
83-
providerPositionOffset uint32
84-
85-
countryEnabled bool
86-
regionEnabled bool
87-
cityEnabled bool
88-
ispEnabled bool
89-
proxyTypeEnabled bool
90-
domainEnabled bool
91-
usageTypeEnabled bool
92-
asnEnabled bool
93-
asEnabled bool
94-
lastSeenEnabled bool
95-
threatEnabled bool
96-
providerEnabled bool
74+
countryPositionOffset uint32
75+
regionPositionOffset uint32
76+
cityPositionOffset uint32
77+
ispPositionOffset uint32
78+
proxyTypePositionOffset uint32
79+
domainPositionOffset uint32
80+
usageTypePositionOffset uint32
81+
asnPositionOffset uint32
82+
asPositionOffset uint32
83+
lastSeenPositionOffset uint32
84+
threatPositionOffset uint32
85+
providerPositionOffset uint32
86+
fraudScorePositionOffset uint32
87+
88+
countryEnabled bool
89+
regionEnabled bool
90+
cityEnabled bool
91+
ispEnabled bool
92+
proxyTypeEnabled bool
93+
domainEnabled bool
94+
usageTypeEnabled bool
95+
asnEnabled bool
96+
asEnabled bool
97+
lastSeenEnabled bool
98+
threatEnabled bool
99+
providerEnabled bool
100+
fraudScoreEnabled bool
97101

98102
metaOK bool
99103
}
100104

101105
var defaultDB = &DB{}
102106

103-
var countryPosition = [12]uint8{0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
104-
var regionPosition = [12]uint8{0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4}
105-
var cityPosition = [12]uint8{0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5}
106-
var ispPosition = [12]uint8{0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6}
107-
var proxyTypePosition = [12]uint8{0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
108-
var domainPosition = [12]uint8{0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7}
109-
var usageTypePosition = [12]uint8{0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8}
110-
var asnPosition = [12]uint8{0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9}
111-
var asPosition = [12]uint8{0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10}
112-
var lastSeenPosition = [12]uint8{0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11}
113-
var threatPosition = [12]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12}
114-
var providerPosition = [12]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13}
115-
116-
const moduleVersion string = "4.0.1"
107+
var countryPosition = [13]uint8{0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3}
108+
var regionPosition = [13]uint8{0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
109+
var cityPosition = [13]uint8{0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
110+
var ispPosition = [13]uint8{0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6}
111+
var proxyTypePosition = [13]uint8{0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
112+
var domainPosition = [13]uint8{0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7}
113+
var usageTypePosition = [13]uint8{0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8}
114+
var asnPosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9}
115+
var asPosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10}
116+
var lastSeenPosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11}
117+
var threatPosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12}
118+
var providerPosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13}
119+
var fraudScorePosition = [13]uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14}
120+
121+
const moduleVersion string = "4.1.0"
117122

118123
var maxIPV4Range = uint128.From64(4294967295)
119124
var maxIPV6Range = uint128.From64(0)
@@ -139,8 +144,9 @@ const as uint32 = 0x00400
139144
const lastSeen uint32 = 0x00800
140145
const threat uint32 = 0x01000
141146
const provider uint32 = 0x02000
147+
const fraudScore uint32 = 0x04000
142148

143-
const all uint32 = countryShort | countryLong | region | city | isp | proxyType | isProxy | domain | usageType | asn | as | lastSeen | threat | provider
149+
const all uint32 = countryShort | countryLong | region | city | isp | proxyType | isProxy | domain | usageType | asn | as | lastSeen | threat | provider | fraudScore
144150

145151
const msgNotSupported string = "NOT SUPPORTED"
146152
const msgInvalidIP string = "INVALID IP ADDRESS"
@@ -446,6 +452,10 @@ func OpenDBWithReader(reader dbReader) (*DB, error) {
446452
db.providerPositionOffset = uint32(providerPosition[dbt]-2) << 2
447453
db.providerEnabled = true
448454
}
455+
if fraudScorePosition[dbt] != 0 {
456+
db.fraudScorePositionOffset = uint32(fraudScorePosition[dbt]-2) << 2
457+
db.fraudScoreEnabled = true
458+
}
449459

450460
db.metaOK = true
451461

@@ -484,6 +494,7 @@ func loadMessage(mesg string) IP2ProxyRecord {
484494
x.LastSeen = mesg
485495
x.Threat = mesg
486496
x.Provider = mesg
497+
x.FraudScore = mesg
487498
x.IsProxy = -1
488499

489500
return x
@@ -586,6 +597,12 @@ func (d *DB) GetProvider(ipAddress string) (string, error) {
586597
return data.Provider, err
587598
}
588599

600+
// GetFraudScore will return the fraud score of the queried IP address.
601+
func (d *DB) GetFraudScore(ipAddress string) (string, error) {
602+
data, err := d.query(ipAddress, fraudScore)
603+
return data.FraudScore, err
604+
}
605+
589606
// IsProxy checks whether the queried IP address was a proxy. Returned value: -1 (errors), 0 (not a proxy), 1 (a proxy), 2 (a data center IP address or search engine robot).
590607
func (d *DB) IsProxy(ipAddress string) (int8, error) {
591608
data, err := d.query(ipAddress, isProxy)
@@ -774,6 +791,12 @@ func (d *DB) query(ipAddress string, mode uint32) (IP2ProxyRecord, error) {
774791
}
775792
}
776793

794+
if mode&fraudScore != 0 && d.fraudScoreEnabled {
795+
if x.FraudScore, err = d.readStr(d.readUint32Row(row, d.fraudScorePositionOffset)); err != nil {
796+
return x, err
797+
}
798+
}
799+
777800
if x.CountryShort == "-" || x.ProxyType == "-" {
778801
x.IsProxy = 0
779802
} else {

0 commit comments

Comments
 (0)