If you need an introduction to C#, you are in the right place. C# is one of the most widely used programming languages today. It is one of the first languages that was developed for Microsoft’s .NET platform and has found its way into almost every other platform. In this post, I will be discussing how to build what is my ip address with csharp.
We can not get our public ip address by ourself nstead we are going to use one of the website that offers our public adddress without any html or java script content and i found this website in stackoverflow called http://icanhazip.com/ that return the ip address
so in order to get the public ip we must download it from the website and to do that we are going to call
so first we create an instance of the class and call it webcall
WebClient webcall = new WebClient();
next we call a method inside the webclient class called DownloadString and this method takes as perameter the url that we are going to download as html and return a string so we need to create a variable that will hold the response and we call public_ip
string public_ip = webcall.DownloadString("http://icanhazip.com");
next we print the result by typing
and then we call the ReadKey to stop the app from closing after the excution of the code complete
Congratulation You found your public ip address
you can trim the response by removing the back line and the return line and you can do that by changing the code to
webcall.DownloadString("http://icanhazip.com").Replace("\r\n", "").Replace("\n", "");
External links are links that direct users to websites other than your own. External links...