lab004

command
v0.0.0-...-f10d331 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 8 Imported by: 0

README

实验4,得到本机和公网ip

我们在测试服务器的时候,经常在本机和外网的服务器上测试,配置文件改起来比较麻烦。 所以准备直接在测试的时候,直接在服务器里面加上得到ip的代码,运行在这个ip上。

设计的目标:

  1. 一般的pc上,直接得到局域网的地址
  2. 在云服务器上,有的云服务器只有10开头的内网,这时候要得到外网的地址(也可以返回0.0.0.0)
  3. 有的云服务器,会有内网和外网两个地址,这时候返回外网
  4. 要去掉docker或者vm的虚拟网卡,和云服务器上的一些虚拟网卡

运行结果

Imgur

参考资料

http://golangtc.com/t/5111b98b320b5209f4000004

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL