如何獲取公網IP


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

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的服務器代碼: https://www.cnblogs.com/wang-li/p/11453633.html)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM