How to get external IP successfully

前端 未结 9 1253
耶瑟儿~
耶瑟儿~ 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 16:55

    Some servers has triggers that blocks access from "non-browsers". They understand that you are some kind of automatic app that can do a DOS attack. To avoid this, you can try to use a lib to access the resource and set the "browser" header.

    wget works in this way:

     wget  -r -p -U Mozilla http://www.site.com/resource.html
    

    Using Java, you can use the HttpClient lib and set the "User-Agent" header. Look the topic 5 of "Things To Try" section.

    Hope this can help you.

提交回复
热议问题