1

Hello.. Using Koltin : I'm trying to access an URL that is Blocked in my country and needs to change the DNS or turn on VPN make a successful connection So :

Is there Any way to change the DNS programmatically or is there any other suitable solution to this problem And that my Code :

val url = URL("https://prices2.herokuapp.com/")
val con=url.openConnection() as HttpURLConnection
con.connectTimeout=5000
val inputstream=con.inputStream
val bufferreader=BufferedReader(InputStreamReader(inputstream))
bufferreader.forEachLine {
                    data+=it
                }
Ammar Hasan
  • 21
  • 1
  • 5
  • [This question/answers](https://stackoverflow.com/questions/11647629/how-to-configure-hostname-resolution-to-use-a-custom-dns-server-in-java) might be helpful, or you could look at other libraries that provide hostname resolution. For example, [OkHttp](https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dns/). – mkobit Jun 08 '21 at 14:18

1 Answers1

0

Use third-part tools (such as dnsjava or minidns) to resolve the ip of your target Hostname. And connect to target server through ip directly.

Ken Lee
  • 41
  • 1
  • 5