zoukankan      html  css  js  c++  java
  • 获取本地连接ip地址(通用版)

    @echo off & setlocal enabledelayedexpansion
    rem 如果系统中有route命令,优先采用方案1:
    for /f "tokens=3,4" %%a in ('route print^|find "0.0.0.0          0.0.0.0"') do (if not defined ip set "Gateway=%%a" & set "ip=%%b")
    for /f "tokens=2" %%a in ('route print^|find "在链路上 %ip%"') do (if not defined mask set "mask=%%a" )
    for /f "tokens=2" %%a in ('route print^|findstr "在链路上.*%ip%"') do (if not defined mask set "mask=%%a" )

    rem 如果系统中没有route命令,就采用方案2:
    if defined ip goto :next
    for /f "delims=[]" %%a in ('ipconfig^|find /n "以太网:"') do if not defined n1 set /a n1=%%a+3
    for /f "delims=[]" %%a in ('ipconfig^|find /n "本地连接:"') do if not defined n1 set /a n1=%%a+3
    set /a n2=%n1%+1
    set /a n3=%n1%+2
    for /f "skip=%n1% tokens=2 delims=:" %%a in ('ipconfig') do if not defined ip set ip=%%a
    for /f "skip=%n2% tokens=2 delims=:" %%a in ('ipconfig') do if not defined mask set mask=%%a
    for /f "skip=%n3% tokens=2 delims=:" %%a in ('ipconfig') do if not defined gate set gate=%%a
    set ip=%ip: =%
    set mask=%mask: =%
    set gate=%gate: =%

    :next
    echo IP地址是:%ip%
    echo 子网掩码是:%mask%
    echo 网关是:%gate%
    pause

  • 相关阅读:
    Servlet梳理一
    String和StringBuffer的区别
    谈谈面对将要来到的第一份工作
    shell grep文本搜索
    Shell cut分割
    python的学习之路:计算
    web端和手机端测试有什么不同
    让TortoiseGit记住帐号密码方法
    操纵IE,模拟用户登录
    MVC路由配置.html不能识别
  • 原文地址:https://www.cnblogs.com/liuzhaoyzz/p/12036827.html
Copyright © 2011-2022 走看看