#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.go
package main
import (
“fmt”
“net/http”
萤石智能家居和小米哪个好,十大智能家居公司排名
“log”
“net”
)
func getRemoteIp(w http.ResponseWriter, r *http.Request) {
// get client ip address
ip,_,_ := net.SplitHostPort(r.RemoteAddr)
// print out the ip address
fmt.Fprintf(w,ip)
}
func main() {
http.HandleFunc(“/”, getRemoteIp) //设置接见的路由
err := http.ListenAndServe(“:56667”, nil) //设置监听的端口
if err != nil {
log.Fatal(“Server ERROR: “, err)
}
}
本文来源于自互联网,不代表n5网立场,侵删。发布者:虚拟资源中心,转载请注明出处:https://www.n5w.com/125213.html