Page 1 of 1

Rewrite chack Maxming GeoIP

Posted: 2020-03-22 16:12
by bagu
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.

Re: Rewrite chack Maxming GeoIP

Posted: 2020-03-22 16:20
by RvdH
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)

Re: Rewrite chack Maxming GeoIP

Posted: 2020-03-22 16:29
by bagu
Oh, it's a good news ;)

Thanks a lot, i'll try to use it.

Re: Rewrite chack Maxming GeoIP

Posted: 2020-03-22 16:39
by palinka

Re: Rewrite chack Maxming GeoIP

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

Another good news ^^

Re: Rewrite chack Maxming GeoIP

Posted: 2020-03-24 22:25
by palinka
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

Re: Rewrite chack Maxming GeoIP

Posted: 2020-03-25 02:00
by bagu
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 ;)