0
votes

I am newbie to nsis installer. I would like to detect the country of the user(via ip) and then depending on the country want to do some actions. I searched in nsis plugins directory but I found only a plugin to detect the ip.

How can I get the country code via ip in nsis ? Thank you

1
Taking apart NSIS, what do you think about? Are you looking for the country code from the TLD of the current host if available (and what about the .com, .edu or .org?), or are counting about looking up the ip in a kind of directory? And how about local unroutable addresses behind a NAT: you would look for the public external ip? - Seki
@Seki would like to get the country code from the ip that the user uses. For example if the user ip located in USA i will get the country code US . If the user located in UK i will get the code GB . It's not necessary to get the country code. Only the country is enought - Stauroula Xalkia

1 Answers

3
votes

Detecting country from IP means you need:

  1. Internet connection
  2. A way to determine the external IP (not counting proxies?)
  3. Access to a IP/Geo database

Why not use the Windows configuration on the local machine:

!include LogicLib.nsh
!define LOCALE_SCOUNTRY 6 ; Localized
!define LOCALE_SENGCOUNTRY 4098
!define LOCALE_SENGLANGUAGE 0x00001001
!define GEOCLASS_NATION 16
!define GEOID_NOT_AVAILABLE -1
!define GEO_ISO2 4
!define GEO_ISO3 5


Section

System::Call 'KERNEL32::GetUserDefaultLangID()i.r0'
DetailPrint LANGID=$0
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SENGCOUNTRY},t.r1,i1000)'
DetailPrint LOCALE_SENGCOUNTRY=$1
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SCOUNTRY},t.r1,i1000)'
DetailPrint LOCALE_SCOUNTRY=$1
System::Call 'KERNEL32::GetLocaleInfo(i$0,i${LOCALE_SENGLANGUAGE},t.r1,i1000)'
DetailPrint LOCALE_SENGLANGUAGE=$1

System::Call 'KERNEL32::GetUserGeoID(i${GEOCLASS_NATION})i.r0'
DetailPrint GEOID=$0
${If} $0 <> ${GEOID_NOT_AVAILABLE} ; Only available if the user has set a country/location
${AndIf} $0 != "error" ; GetUserGeoID is WinXP+
    System::Call 'KERNEL32::GetGeoInfo(i$0,i${GEO_ISO2},t.r1,i1000,i0)'
    DetailPrint GEO_ISO2=$1
    System::Call 'KERNEL32::GetGeoInfo(i$0,i${GEO_ISO3},t.r1,i1000,i0)'
    DetailPrint GEO_ISO3=$1
${EndIf}

SectionEnd