Skip to content

Commit

Permalink
Add a handy function for determining if an IP is private for later
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Sep 24, 2016
1 parent acc4e84 commit 96642e5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions HomeAssistant/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ func migrateUserDefaultsToAppGroups() {

}

func checkIfIPIsInternal(ipAddress: String) -> Bool {
let pat = "/(^127\\.)|(^192\\.168\\.)|(^10\\.)|(^172\\.1[6-9]\\.)|(^172\\.2[0-9]\\.)|(^172\\.3[0-1]\\.)|(^::1$)|(^[fF][cCdD])/"
let regex = try! NSRegularExpression(pattern: pat, options: [])
let matches = regex.matches(in: ipAddress, options: [], range: NSRange(location: 0, length: ipAddress.characters.count))
return (matches.count > 0)
}

extension UIImage{
func scaledToSize(_ size: CGSize) -> UIImage{
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
Expand Down

0 comments on commit 96642e5

Please sign in to comment.