Skip to content

Instantly share code, notes, and snippets.

@xmsz
Last active December 10, 2020 02:31
Show Gist options
  • Save xmsz/6e6d60570926956d2249c88b1044b844 to your computer and use it in GitHub Desktop.
Save xmsz/6e6d60570926956d2249c88b1044b844 to your computer and use it in GitHub Desktop.
isLocalIP - 判断当前是不是本地ip
// 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