0

I need to get port protocol details from a URL. Can some one please help me? I have tried with some code -

 Uri uri = new Uri("http://stackoverflow.com/questions/ask");
        string requested = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;

Problem 1 - This code does not tell me whether this is TCP or UDP or ISMP

Problem 2 - This code does not check the actual port/protocol details of the URL.

Problem 3 - I am not able to build the URL if I have URL like this - "stackoverflow.com".

Please some one help me.

Thanks Gulrej

2
  • "stackoverflow.com" is not a URL, it's a hostname. You have to assume, guess or decide the other information. Commented Apr 4, 2016 at 5:52
  • Ok that I understand. But if I have a full URL , can I know whether it is TCP/UDP or ISMP ?
    – Gulrej
    Commented Apr 4, 2016 at 5:59

2 Answers 2

3

This may help, It worked for me

string url = "http://www.contoso.com:8080/letters/readme.html";

 Regex r = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/",
                          RegexOptions.None, TimeSpan.FromMilliseconds(150));
      Match m = r.Match(url);
      if (m.Success)
         Console.WriteLine(r.Match(url).Result("${proto}${port}")); 
3
0

With url = stackoverflow.com/questions/ask

You're easily to know :

Protocol = http or https.

And

Port = default port = 80 (http) or 443 (https)

In case having the specific port,it will be placed after hostname like this [stackoverflow.com:8180]

3
  • Can you please post me some sample code? And i want to know the TCP/UDP/ISMP of this request also.
    – Gulrej
    Commented Apr 4, 2016 at 6:30
  • TCP is a transport layer protocol , and HTTP is an application layer protocol that run over TCP. Commented Apr 4, 2016 at 6:50
  • So is it possible to fetch those information using C# asp.net
    – Gulrej
    Commented Apr 4, 2016 at 7:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.