NSIS通过IP检测国家代码

时间:2013-01-08 18:08:30

标签: installation nsis

我是nsis安装程序的新手。我想检测用户的国家(通过IP),然后根据国家想要做一些动作。我搜索了nsis插件目录,但我发现只有一个插件来检测ip。

如何在nsis中通过ip获取国家/地区代码? 谢谢

1 个答案:

答案 0 :(得分:3)

从IP检测国家/地区意味着您需要:

  1. 互联网连接
  2. 确定外部IP的方法(不计算代理?)
  3. 访问IP /地理数据库
  4. 为什么不在本地计算机上使用Windows配置:

    !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