npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-networkinterface

v2.2.0

Published

Cordova Networkinterface Plugin

Readme

cordova-plugin-networkinterface

一款专为 Cordova 混合移动应用打造的网络接口信息获取插件,支持跨平台获取设备网络适配器的详细信息,包括IP地址、MAC地址、子网掩码、网关等关键网络参数,助力开发者实现网络诊断、设备绑定等场景化需求。

功能特性

  • 全面的网络信息获取:支持获取所有网络适配器的IP地址(IPv4/IPv6)、MAC地址、子网掩码、网关、DNS服务器等完整参数

  • 多适配器识别:自动识别Wi-Fi、以太网、移动数据(4G/5G)、蓝牙共享等不同类型的网络适配器

  • 活跃网络检测:快速定位当前设备正在使用的活跃网络适配器,避免无效信息干扰

  • 跨平台一致性:在Android、iOS、Browser、OHOS平台提供统一API,屏蔽平台差异,降低开发成本

  • 完整错误处理:针对权限不足、网络未连接等场景提供明确错误信息,便于问题定位

安装方法

确保已创建 Cordova 项目(若未创建,执行 cordova create networkApp com.example.networkapp NetworkApp 创建),进入项目根目录后选择以下方式安装:

1. 基础安装

# 安装hcordova
npm install -g hcordova

# 安装最新稳定版插件
hcordova plugin add cordova-plugin-networkinterface

# 指定OHOS安装
hcordova plugin add cordova-plugin-networkinterface --platform ohos

# 安装指定版本(示例:1.0.0 版本)
hcordova plugin add [email protected] --platform ohos

2. 从 GitCode 安装开发版

适用于需要体验最新功能的开发者,从 GitHub 仓库直接安装:


# 安装开发版插件
hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-networkinterface.git --platform ohos

3. 安装后验证

安装完成后,可通过以下命令验证插件是否安装成功:


# 查看已安装的插件列表
cordova plugin list

# 若列表中显示 cordova-plugin-networkinterface 则安装成功

卸载方法

进入项目根目录,执行以下命令卸载插件,卸载后建议重新构建项目以清理残留的原生配置文件:


# 全平台卸载网络接口插件
cordova plugin remove cordova-plugin-networkinterface

# 指定OHOS卸载
cordova plugin remove cordova-plugin-networkinterface  --platform ohos

API 参考

插件通过全局对象 cordova.plugins.networkInterface 暴露所有 API 方法,所有操作均需在 deviceready 事件触发后调用。支持回调函数和 Promise 两种调用方式(示例以 Promise 为主,回调方式可参考快速开始)。

1. 获取wifi的IP地址

获取当前设备正在使用的活跃网络适配器的IP地址信息,当前仅支持IPv4。

//返回ip地址和子网掩码
networkinterface.getWiFiIPAddress(function(ipInformation){
    document.getElementById("wifiIp").innerHTML = "IP: " + ipInformation.ip + " subnet:" + ipInformation.subnet;
},function(error){
    document.getElementById("wifiIp").innerHTML = error;
})

返回结果(IP信息对象):


{
  "ip": "192.168.1.100", // IP地址
  "subnet": "255.255.255.0", // 子网掩码
}

2. 获取蜂窝网络的IP地址和子网掩码

获取当前连接的Wi-Fi网络详细信息,包括SSID、MAC地址、信号强度等(需对应权限)。


networkinterface.getCarrierIPAddress(function(ipInformation){
    document.getElementById("4GIp").innerHTML = "IP: " + ipInformation.ip + " subnet:" + ipInformation.subnet;
},function(error){
    document.getElementById("4GIp").innerHTML = error;
})

返回结果(IP信息对象):


{
  "ip": "192.168.1.100", // IP地址
  "subnet": "255.255.255.0", // 子网掩码
}

3. 获取代理信息


function getHttpProxyInformation() {
    networkinterface.getHttpProxyInformation("http://www.***.com", function(proxy){
        document.getElementById("proxy").innerHTML = "type: " + proxy.type + " host:" + proxy.host+" port:"+proxy.port;
    },function(error){
        document.getElementById("proxy").innerHTML = error;
    })
}

返回结果(适配器列表):


{
  "type": "1", //1:配置有代理,0:无代理直连方式
  "host": "192.168.1.100", // 返回代理地址
  "port":8090 //返回代理端口
}

许可证

本插件基于 Apache License 开源,详见 LICENSE 文件。

参考资源