sf-utils2 sf-utils2
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
  • 快速开始

  • 基础-Base

  • 对象-Object

  • 数组-Array✨✨✨

  • 方法-Function

  • 字符串-String

  • 数学-Math

  • 文件-Buffer

  • 节点-dom

  • 拓展

  • nodejs

    • 序言 👏
    • getIpAddrSync【获取本地局域网ip地址】
      • 1.示例
      • 2.入参说明
      • 3.源码
    • readDirStructureSync【获取所有子文件,递归】
  • 指南
  • nodejs
bianpengfei
2023-01-02
目录

getIpAddrSync【获取本地局域网ip地址】

描述

获取本地局域网 ip 地址 🎉🎉🎉

# 1.示例

const { getIpAddrSync } = require('sf-utils2/lib/nodejs')

console.log('getIpAddrSync', getIpAddrSync()) // getIpAddrSync 192.168.0.101
1
2
3
  • 图片

# 2.入参说明

参数 说明 类型 是否必填 默认值

# 3.源码

const os = require('os')

/**
 * 获取ip
 * @returns {string}
 */
function getIPAddressSync() {
  const interfaces = os.networkInterfaces()
  for (const devName in interfaces) {
    const iface = interfaces[devName]
    for (let i = 0; i < iface.length; i++) {
      const alias = iface[i]
      if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
        return alias.address
      }
    }
  }
}

module.exports = getIPAddressSync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
上次更新: 2025/07/01, 14:52:29
序言 👏
readDirStructureSync【获取所有子文件,递归】

← 序言 👏 readDirStructureSync【获取所有子文件,递归】→

Theme by Vdoing | Copyright © 2022-2025 bianpengfei
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×