Skip to content

Commit

Permalink
Add IPLocation Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWanderingCoel committed Jun 21, 2019
1 parent cd310f6 commit 4b6f5e6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ShadowCoel/Utils/IPLocation.swift
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
}

}

0 comments on commit 4b6f5e6

Please sign in to comment.