如何獲取公網IP

地址: http://ip.wang-li.top:93/4u6385IPhtml

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)
        }
    }
}

 (自建返回IP的服務器代碼: http://www.javashuo.com/article/p-uuueherj-gq.html)python

相關文章
相關標籤/搜索