Last active
December 10, 2020 02:31
-
-
Save xmsz/6e6d60570926956d2249c88b1044b844 to your computer and use it in GitHub Desktop.
isLocalIP - 判断当前是不是本地ip
This file contains hidden or 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
// url可传入window.location.origin进行判断 | |
const isLocalIp = (url: string) => { | |
const resultUrl = url.replace(/(http|ftp|https|www):\/\//g, ''); | |
return ( | |
resultUrl.startsWith('192.') || | |
resultUrl.startsWith('172.') || | |
resultUrl.startsWith('10.') || | |
resultUrl.startsWith('localhost') | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment