I'm making an app that uses SpotifyAPI-NET, but I want all my application internet calls to use a custom DNS(not the windows configured) because Spotify has blocked access to its services for some countries(including Iran where I live) and there's a DNS that makes it possible for me to use Spotify service.
-
Possible duplicate of [Specify which DNS servers to use to resolve hostnames in .NET](https://stackoverflow.com/questions/1315758/specify-which-dns-servers-to-use-to-resolve-hostnames-in-net) – frido Mar 18 '19 at 14:09
1 Answers
I guess the answer depends on what you want to do. Do you want to : 1) Have you app make its DNS call on a different DNS server than the rest of the system? 2) Change the DNS server for the whole system?
If you want to achieve 1), you would need to modify the source code of SpotifyAPI-NET. On every occurence of a Spotify API url string, you should make a call to a custom-made DNS resolver to obtain the IP address, and replace the hostname by said IP. You can find an example of custom-made DNS call in C# here : https://www.codeproject.com/Articles/23673/DNS-NET-Resolver-C
If you want to achieve 2), you can find some example here: How can you change Network settings (IP Address, DNS, WINS, Host Name) with code in C#
I think 2) would be much easier to maintain because it would not require patching a third-party plugin, but you may have reasons to want to avoid 2), for instance if you need to use a DNS different from the one allowing Spotify to access, say, Iranian governmental websites, maybe?

- 180
- 11