如何获取公网ip,自己搭建公网ip服务器的方法

如何获取公网ip,自己搭建公网ip服务器的方法,第1张

如何获取公网ip,自己搭建公网ip服务器的方法 #Go语言初体验 – 获取公网IP小服务。


由于免费的动态dns刷新IP很慢, 手动实时获取办公室网络公网IP。


#GetIp.go 是服务端程序, 用于返回当前访问的请求的公网IP。


demo地址: http://47.52.66.195:56667/#安装go环境yum install -y go#下载源码包wget https://github.com/liuhu/PublicIpServer/raw/master/GetIp.go#运行脚本go run Getip.go &评论说说大家最喜欢的语音go ? python? java? php ?或者什么?源代码如下cat GetIp.gopackage mainimport (“fmt”“net/http”“log”“net”)func getRemoteIp(w http.ResponseWriter, r *http.Request) {// get client ip addressip,_,_ := net.SplitHostPort(r.RemoteAddr)// print out the ip addressfmt.Fprintf(w,ip)}func main() {http.HandleFunc(“/”, getRemoteIp) //设置访问的路由err := http.ListenAndServe(“:56667”, nil) //设置监听的端口if err != nil {log.Fatal(“Server ERROR: “, err)}}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/594662.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-13
下一篇 2022-04-13

发表评论

登录后才能评论

评论列表(0条)

保存