若何获取公网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.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)

}

}

用Go语言写一个获取公网ip的接口

本文来源于自互联网,不代表n5网立场,侵删。发布者:虚拟资源中心,转载请注明出处:https://www.n5w.com/125213.html

(0)
打赏 微信扫一扫 微信扫一扫
虚拟资源中心虚拟资源中心网络小白
上一篇 2020年6月21日 22:48
下一篇 2020年6月21日 22:48

相关推荐

联系我们

电话:

在线咨询:点击这里给我发消息

邮件:@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

公众号