From 766b2bd00754b5d30f14d904c94709f982b4ff95 Mon Sep 17 00:00:00 2001 From: fengbh <1953356163@qq.com> Date: Tue, 22 Apr 2025 10:20:44 +0800 Subject: [PATCH] use curl not nslookup --- vim/.vimrc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vim/.vimrc b/vim/.vimrc index 9a74c94..5ce88e1 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -3,20 +3,20 @@ " License : MIT " Author : Feng Bohan <1953356163@qq.com> " Date : 2025-04-18 08:39:57 -" Last Modified Date: 2025-04-21 16:47:19 +" Last Modified Date: 2025-04-22 10:19:39 " Last Modified By : Feng Bohan <1953356163@qq.com> " Copyright © 2025 Shanghai Fudan Microelectronics Group Co.,Ltd. All Rights Reserved. " 环境检测 function! IsAtCompany() " 检查 baidu.com 是否能解析 - let l:cmd = 'nslookup baidu.com >/dev/null 2>&1' + let l:cmd = 'curl -s -o /dev/null -m 2 -w "%{http_code}" https://baidu.com' + let l:http_code = system(l:cmd) - " 执行命令,返回 0 表示解析成功(不在公司),非 0 表示解析失败(在公司) - if system(l:cmd) == 0 - return 0 " 能解析,不在公司 - else + if match(l:http_code, '^[23][0-9][0-9]$') == -1 return 1 " 不能解析,在公司 + else + return 0 " 能解析,不在公司 endif endfunction " 只在 Vim 启动时检测一次