Cary Bondoc
Cary Bondoc

Reputation: 2988

How to get the desired octet in an IP address that includes port number?

If I have this kind of IP address 192.168.110.128 the way to get the desired octet is already answered here, but it's not applicable to the IP that includes port number like this 192.168.110.128:60423.

Upvotes: 1

Views: 346

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

You can't parse this into an IPAddress object as port is not part of the IP address. It belongs to TCP/UDP.

Instead you will have to parse it into a URI and then get the host value of that, parse that into an IPAddress and there you go:

    Dim address As String = "192.168.110.128:60423"
    Dim ip = IPAddress.Parse(New Uri("http://" & address).Host)
    Debug.WriteLine(ip.GetAddressBytes(3))

Upvotes: 1

Related Questions