0

I just want to get current system IP from Cloudfare from a console application. I looked a lot of online resources, but I couldn't find any working piece of code with HTTPS protocol.

Module Module1

    Sub Main()
        Dim client As New System.Net.WebClient
        Dim data As String = client.DownloadString("https://1.1.1.1/cdn-cgi/trace")
        Console.WriteLine(data)
    End Sub

End Module

But it doesn't work and throws a very long error. I don't know how to fix it.

enter image description here

  • Post the error text, not images of the error. Which .NET version are you using, on which OS? Most likely, the service is using TLS1.2 but the .NET version and/or OS don't support it. If you google for this error message you'll find a *lot* of duplicates from 5 years ago. That's when all major web services started requiring TLS1.2 – Panagiotis Kanavos May 13 '21 at 10:54
  • 1
    The code shown works when I try it using Visual Studio 2017, .NET Framework 4.8, on Windows 10. – Andrew Morton May 13 '21 at 10:54
  • Most likely you're using unsupported Windows *and* .NET versions. The oldest supported Windows version is Windows 10, which uses TLS1.2 automatically. TLS1.2 was added in .NET 4.5 but automatic use was added in 4.6. The earliest supported .NET version is 4.5.2 but even 4.6.1 goes [out of support](https://learn.microsoft.com/en-us/lifecycle/products/microsoft-net-framework) in a year. – Panagiotis Kanavos May 13 '21 at 11:00
  • I posted the error, but it was not letting me post that, saying "your submission looks like has code only add some description" Here is the complete stack trace: https://paste.ee/p/Q2ZBx –  May 13 '21 at 11:01
  • I am on Windows 8.1, Visual Studio 2015. –  May 13 '21 at 11:02
  • So 100% unsupported. Again *post the error as text*. The important parts are truncated. There may be a different error caused by an invalid certificate – Panagiotis Kanavos May 13 '21 at 11:02
  • @PanagiotisKanavos so what should I do to make it work with current OS and VS version? Or it won't work. I added the pastee ink in above comment –  May 13 '21 at 11:04
  • The version of Vislua Studio doesn't specify the version of the .NET Framework. VS 2015 could be used to create .NET 2 applications as well. Which *.NET Framework* version are you targeting? And again, post the actual error. You may be able to patch Windows 8 to work with TLS1.2, but really you should just move to a supported OS and .NET version – Panagiotis Kanavos May 13 '21 at 11:06
  • Target framework is set to 4.5.2 –  May 13 '21 at 11:07
  • The real solution is to stop using unsupported OS and .NET versions. Use at least 4.6.2. You'll have to upgrade in 1 year anyway. Besides. .NET 4.x versions are binary replacements so your customers and clients probably already run on fresher runtimes. If search SO for that error message you'll find a lot of duplicates from 5-6 years ago – Panagiotis Kanavos May 13 '21 at 11:11
  • There's a lot of documentation and MS articles on how to enable TLS 1.2 too, like [How to enable TLS 1.2 on clients](https://learn.microsoft.com/en-us/mem/configmgr/core/plan-design/security/enable-tls-1-2-client) – Panagiotis Kanavos May 13 '21 at 11:13
  • @PanagiotisKanavos Thank you for your help. I have Windows 10 ISO, so I will just install that. –  May 13 '21 at 11:16

0 Answers0