怎样设置静态ip?

请先 登录 后评论

1 个回答

Luffy

首先使用full-sdk,可以在我司百度网盘下载

参考如下方法:

import ethernet from '@ohos.net.ethernet'

onCreate(want, launchParam) {

  let InterfaceConfiguration: ethernet.InterfaceConfiguration = {

    mode: ethernet.IPSetMode.STATIC,

    ipAddr: "192.168.0.2",

    route: "192.168.0.1",

    gateway: "192.168.0.1",

    netMask: "255.255.255.0",

    dnsServers: "8.8.8.8",

  }


  try {

    ethernet.setIfaceConfig("eth0", InterfaceConfiguration).then(() => {

      console.log("setIfaceConfig promiss ok ");

    }).catch((error) => {

      console.error("setIfaceConfig promiss error = " + error);

    });

  } catch (err) {

    console.error("error = " + err);

  }

}

==========================================

module.json5增加权限:

"requestPermissions": [

  {

    "name": "ohos.permission.CONNECTIVITY_INTERNAL",

    "reason": "$string:reason",

    "usedScene": {

      "abilities": [

        "FormAbility"

      ],

      "when": "inuse"

    }

  }

]


==========================================

修改系统签名:

SDK_PATH/toolchains\lib\UnsgnedReleasedProfileTemplate.json

++ "apl":"system basic",


==========================================

删除掉当前签名文件:C:\Users\xxx.ohos\config\openharmony

再重新签名即可

注:设置为静态IP,只能局域网访问网络,外网不通


==========================================

请先 登录 后评论