How to get external IP successfully

前端 未结 9 1278
耶瑟儿~
耶瑟儿~ 2020-12-03 16:16

After reading: Getting the 'external' IP address in Java

code:

public static void main(String[] args) throws IOException
{
    URL whatismyip         


        
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 17:09

    While playing with Go I saw your question. I made a quick App on Google App Engine using Go:

    Hit this URL:

    http://agentgatech.appspot.com/

    Java code:

    new BufferedReader(new InputStreamReader(new URL('http://agentgatech.appspot.com').openStream())).readLine()
    

    Go code for the app which you can copy and make your own app:

    package hello
    
    import (
        "fmt"
        "net/http"
    )
    
    func init() {
        http.HandleFunc("/", handler)
    }
    
    func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, r.RemoteAddr)
    }
    

提交回复
热议问题