File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4747 <Folder Include =" Properties\" />
4848 </ItemGroup >
4949
50+ <ItemGroup >
51+ <PackageReference Include =" MaxMind.GeoIP2" Version =" 5.1.0" />
52+ </ItemGroup >
53+
5054 <ItemGroup >
5155 <ProjectReference Include =" ..\..\vendor\MBNCSUtil\src\MBNCSUtil.csproj" />
5256 </ItemGroup >
Original file line number Diff line number Diff line change @@ -169,6 +169,33 @@ public void Dispose() /* part of IDisposable */
169169 IsDisposing = false ;
170170 }
171171
172+ public void GenerateLocaleFromGeoIP ( )
173+ {
174+ var file = Path . GetFullPath ( Path . Combine ( AppContext . BaseDirectory , "GeoIP2-City.mmdb" ) ) ;
175+ // This creates the DatabaseReader object, which should be reused across
176+ // lookups.
177+ using ( var reader = new MaxMind . GeoIP2 . DatabaseReader ( file ) )
178+ {
179+ // Replace "City" with the appropriate method for your database, e.g.,
180+ // "Country".
181+ var city = reader . City ( ( Client . RemoteEndPoint as IPEndPoint ) . Address . ToString ( ) ) ;
182+
183+ Console . WriteLine ( city . Country . IsoCode ) ; // 'US'
184+ Console . WriteLine ( city . Country . Name ) ; // 'United States'
185+ Console . WriteLine ( city . Country . Names [ "zh-CN" ] ) ; // '美国'
186+
187+ Console . WriteLine ( city . MostSpecificSubdivision . Name ) ; // 'Minnesota'
188+ Console . WriteLine ( city . MostSpecificSubdivision . IsoCode ) ; // 'MN'
189+
190+ Console . WriteLine ( city . City . Name ) ; // 'Minneapolis'
191+
192+ Console . WriteLine ( city . Postal . Code ) ; // '55455'
193+
194+ Console . WriteLine ( city . Location . Latitude ) ; // 44.9733
195+ Console . WriteLine ( city . Location . Longitude ) ; // -93.2323
196+ }
197+ }
198+
172199 public byte [ ] GenerateStatstring ( )
173200 {
174201 byte [ ] statstring = null ;
You can’t perform that action at this time.
0 commit comments