We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有的时候我们需要知道我们本地机器的ip地址。
前端项目大部分都是通过localhost:端口号来运行的,但是比如我们要写RN的时候,在安卓模拟器中的我们可能就不能直接使用localhost或127.0.0.1,使用的应该是局域网给我们动态分配的ip地址。
localhost
127.0.0.1
下面介绍两种三种方式获得动态分配的ip地址:
打开偏好设置,点击网络
红框圈起来的就是ip地址
terminal
ifconfig
ipconfig
每次链接wifi的时候,我们的ip可能就会被重新分配,每次去走上面一遍可能会比较麻烦,有没有上面比较高级的方式获取呢。
address
npm init -y npm install --save-dev
为了演示简单,单独写一个文件,例如:getIpAddress.js
const address = require('address') console.log(address.ip())
使用node运行。
有了上述的方法,我们就可以在程序启动的时候,告诉开发者(我们自己)当前的ip地址是多少,我们就能直接去模拟器中打开了。 address包还可以获取IPv6和MAC地址。详细查看 address-npm
IPv6
MAC
The text was updated successfully, but these errors were encountered:
No branches or pull requests
有的时候我们需要知道我们本地机器的ip地址。
前端项目大部分都是通过localhost:端口号来运行的,但是比如我们要写RN的时候,在安卓模拟器中的我们可能就不能直接使用
localhost
或127.0.0.1
,使用的应该是局域网给我们动态分配的ip地址。下面介绍两种三种方式获得动态分配的ip地址:
图形化获取
打开偏好设置,点击网络
![](https://raw.githubusercontent.com/kuckboy1994/Blog/master/images/node/getIpAddress/ip1.png)
红框圈起来的就是ip地址
![](https://raw.githubusercontent.com/kuckboy1994/Blog/master/images/node/getIpAddress/ip2.png)
命令行获取
terminal
输入
ifconfig
。注意不是ipconfig
程序获取
每次链接wifi的时候,我们的ip可能就会被重新分配,每次去走上面一遍可能会比较麻烦,有没有上面比较高级的方式获取呢。
address
包为了演示简单,单独写一个文件,例如:getIpAddress.js
使用node运行。
![](https://raw.githubusercontent.com/kuckboy1994/Blog/master/images/node/getIpAddress/ip4.png)
有了上述的方法,我们就可以在程序启动的时候,告诉开发者(我们自己)当前的ip地址是多少,我们就能直接去模拟器中打开了。
![](https://raw.githubusercontent.com/kuckboy1994/Blog/master/images/node/getIpAddress/ip5.png)
address
包还可以获取IPv6
和MAC
地址。详细查看 address-npmThe text was updated successfully, but these errors were encountered: