-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TheWanderingCoel
committed
Jun 21, 2019
1 parent
cd310f6
commit 4b6f5e6
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// IPLocation.swift | ||
// ShadowCoel | ||
// | ||
// Created by Coel on 2019/6/14. | ||
// Copyright © 2019 CoelWu. All rights reserved. | ||
// | ||
|
||
import MMDB_Swift | ||
|
||
class IPLocation { | ||
|
||
open func IP2CountryCode(IP: String) -> String? { | ||
|
||
var countrycode:String? = "" | ||
|
||
guard let db = MMDB() else { | ||
DDLogError("Failed to open DB.") | ||
return "" | ||
} | ||
|
||
if let country = db.lookup(IP) { | ||
countrycode = country.isoCode | ||
} | ||
|
||
if countrycode == "" { | ||
countrycode = "WW" | ||
} | ||
|
||
return countrycode | ||
} | ||
|
||
} |