Rewrite chack Maxming GeoIP

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
User avatar
bagu
Normal user
Normal user
Posts: 219
Joined: 2005-06-17 03:08
Location: France
Contact:

Rewrite chack Maxming GeoIP

Post by bagu » 2020-03-22 16:12

Hi,

I'm looking to update this script :
https://www.hmailserver.com/forum/viewt ... 9&start=60

But, Maxmind now use mmdb format.
Do you know how to use it trought vbs script ?

Here is my old script :

Code: Select all

'   Sub OnClientConnect(oClient)
Function ListedInAbuseIPDB(strIP) : ListedInAbuseIPDB = false
	With CreateObject("AbuseIPDBComponent.AbuseIPDBRestClient")
		.SetApiKey("MY_API_KEY")
		.SetMaxConfidenceScore(50)
		.SetMaxAgeInDays(30)
		On Error Resume Next
		ListedInAbuseIPDB = .BlockEndpoint(strIP)
		If (ListedInAbuseIPDB) then
			EventLog.Write("AbuseIPDB Score:" & .GetConfidenceScore(strIP))
		End If
		If Err.Number <> 0 Then
			EventLog.Write("AbuseIPDB Error: " & Err.Description)
		End If
		On Error Goto 0
	End With
End Function

Sub OnClientConnect(oClient)
	' GeoIP
	Dim geoip
	Result.Value = 0
	set geoip = CreateObject("GeoIPCOMEx.GeoIPEx")
	geoip.set_db_path("D:\geoip\")
	geoip.find_by_addr(oClient.IPAddress)
	country = geoip.country_code

	Select Case country
		Case "RU","CN","PA","ID","AR","VN","TR","NC","RO","GR","EG","NP"
			Result.Value = 1
			EventLog.Write("Geo-IP rejected:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34)+geoip.country_code+" "+geoip.country_name)
		Case Else
			If ListedInAbuseIPDB(oClient.IPAddress) Then
				EventLog.Write("INFO: AbuseIPDB: " & oClient.IPAddress & ":" & oClient.Port & " " & country & " " & geoip.country_name)	
				Result.Value = 1
				Exit Sub
			End If
	End Select
End Sub
'   End Sub
The goal is to disconnect client from non-autorised country before IPDB checking.

Can you help me ?

An other way to do something similar is to import GeoLite2-Country-Blocks-IPv4.csv , GeoLite2-Country-Blocks-IPv6.csv and GeoLite2-Country-Locations-fr.csv (in FR for me ;) ) to mysql database and find a way to use it trough vbs...

But again, i don't know to do this.
Last edited by bagu on 2020-03-22 16:20, edited 1 time in total.
hMailServer 5.6.8 With SpamAssassin 3.4.2

User avatar
RvdH
Senior user
Senior user
Posts: 1078
Joined: 2008-06-27 14:42
Location: Netherlands

Re: Rewrite chack Maxming GeoIP

Post by RvdH » 2020-03-22 16:20

You can still use legacy format, i get mine from here https://mailfud.org/geoip-legacy/ (but there are more/others providing legacy formatted db)
CIDR to RegEx: d-fault.nl/CIDRtoRegEx
DNS Lookup: d-fault.nl/DNSTools
DNSBL Lookup: d-fault.nl/DNSBLLookup
GEOIP Lookup: d-fault.nl/GeoipLookup

User avatar
bagu
Normal user
Normal user
Posts: 219
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: Rewrite chack Maxming GeoIP

Post by bagu » 2020-03-22 16:29

Oh, it's a good news ;)

Thanks a lot, i'll try to use it.
hMailServer 5.6.8 With SpamAssassin 3.4.2

palinka
Senior user
Senior user
Posts: 1942
Joined: 2017-09-12 17:57

Re: Rewrite chack Maxming GeoIP

Post by palinka » 2020-03-22 16:39


User avatar
bagu
Normal user
Normal user
Posts: 219
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: Rewrite chack Maxming GeoIP

Post by bagu » 2020-03-22 16:48

Oh, i missed this post...

Another good news ^^
hMailServer 5.6.8 With SpamAssassin 3.4.2

palinka
Senior user
Senior user
Posts: 1942
Joined: 2017-09-12 17:57

Re: Rewrite chack Maxming GeoIP

Post by palinka » 2020-03-24 22:25

bagu wrote:
2020-03-22 16:48
Oh, i missed this post...

Another good news ^^
I just did a big update with some bug fixes. If you're using it, you should get the new one.

https://github.com/palinkas-jo-reggelt/GeoLite2SQL

User avatar
bagu
Normal user
Normal user
Posts: 219
Joined: 2005-06-17 03:08
Location: France
Contact:

Re: Rewrite chack Maxming GeoIP

Post by bagu » 2020-03-25 02:00

I'll take a look in it.

But, i will stay on geoip.dat for the moment, because everything is on the .vbs script and i want to avoid adding more task in my scheduler ;)
hMailServer 5.6.8 With SpamAssassin 3.4.2

Post Reply