客户端
Linux:
# curl http://ip.wang-li.top:93/4u6385IP
Python
#!/usr/bin/env python3
import requests
def main():
url = "http://ip.wang-li.top:93/4u6385IP"
MyIP = requests.get(url).text
print(MyIP)
if __name__ == '__main__':
main()
Go
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "http://ip.wang-li.top:93/4u6385IP"
resp , err := http.Get(url);if err != nil {
fmt.Println("Http Connect Error", err)
} else {
b , err := ioutil.ReadAll(resp.Body); if err != nil {
fmt.Println("Read Body Error" , err)
} else {
fmt.Printf("%s",b)
}
}
}
Lua
#!/usr/bin/lua5.3
http = require("socket.http")
function ReturnIP(url)
local resp = http.request(url)
return resp
end
print(ReturnIP('http://ip.wang-li.top:93/4u6385IP'))
服务器
Go服务器
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"strings"
"time"
)
const LoveChina = "富强,民主,文明,和谐。 自由,平等,公正,法治。 爱国,敬业,诚信,友善。"
var (
h bool
LitenAddr string
ListenRoute string
)
func init() {
flag.BoolVar(&h,"h",false,"This help")
flag.StringVar(&LitenAddr,"ListenAddr","0.0.0.0:93","Set http server listen address")
flag.StringVar(&ListenRoute,"ListenRoute","/4u6385IP","Set http server listen Route")
}
func OutIPAddress(w http.ResponseWriter, r *http.Request) {
if "GET" == r.Method {
slice01 := strings.Split(r.RemoteAddr,":")
fmt.Fprintf(w,slice01[0])
log.Println(time.Now(),"-- 4u6385IP --",r)
log.Println(time.Now(),"RemoteAdd",slice01[0])
} else {
fmt.Fprintf(w,LoveChina)
log.Println(time.Now() , r.RemoteAddr, LoveChina)
}
}
func main() {
flag.Parse()
if h {
flag.Usage()
os.Exit(0)
}
if ! strings.HasPrefix(ListenRoute,"/") {
ListenRoute = "/" + ListenRoute
}
http.HandleFunc(ListenRoute,OutIPAddress)
log.Println("Server running on http://" + LitenAddr + ListenRoute)
s := &http.Server{
Addr: LitenAddr,
ReadTimeout:10*time.Second,
WriteTimeout:10*time.Second,
MaxHeaderBytes:1<<20,
}
log.Fatal(s.ListenAndServe())
}
来源:oschina
链接:https://my.oschina.net/wangyli/blog/3164983