Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Socket issue

C# Socket issue

Scheduled Pinned Locked Moved C#
csharphelpdebuggingperformancequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dotman1
    wrote on last edited by
    #1

    I am having difficulty filtering IP Addresses using IPAddress.TryParse() I am trying to get upto speed with .NET programming, running MSVS 2005 .NET on Vista Home Pro. System Config Notebook one ethernet + built-in WiFi. On form load I request Internet Host Info and aquire numerous addresses, and add them to the listbox for selection later. The problem some do not reflect a true IP address are varied lengths some look like partial mac adresses etc, and are invalid for speific reasons hense the need to filter them. Having stepped through debug I am now assuming the reason IPAddress.TryParse() is not filtering them is because the values are valid based on the AddressList[] static members: Any, Broadcast, IPv6Any ... the list continues. Identifying IPv6Loopback as being the problem for the following scenario because IPv6Loopback contains {::1} For simplicity, with no ethernet connection & WiFi disabled; I have 2 items in the listbox: ::1 (I regard as a problem) 127.0.0.1 (Loopback no problem) The code: string strIP = null; IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); if (hostEntry.AddressList.Length > 0) { foreach (IPAddress ip in hostEntry.AddressList) { strIP = ip.ToString(); IPAddress tmpAddress; if (IPAddress.TryParse(strIP, out tmpAddress)) { socketListBox.Items.Add(strIP); } } } If my assumtion is correct how can I filter the items which cause phyical issues. Regards

    dotman1

    H 1 Reply Last reply
    0
    • D dotman1

      I am having difficulty filtering IP Addresses using IPAddress.TryParse() I am trying to get upto speed with .NET programming, running MSVS 2005 .NET on Vista Home Pro. System Config Notebook one ethernet + built-in WiFi. On form load I request Internet Host Info and aquire numerous addresses, and add them to the listbox for selection later. The problem some do not reflect a true IP address are varied lengths some look like partial mac adresses etc, and are invalid for speific reasons hense the need to filter them. Having stepped through debug I am now assuming the reason IPAddress.TryParse() is not filtering them is because the values are valid based on the AddressList[] static members: Any, Broadcast, IPv6Any ... the list continues. Identifying IPv6Loopback as being the problem for the following scenario because IPv6Loopback contains {::1} For simplicity, with no ethernet connection & WiFi disabled; I have 2 items in the listbox: ::1 (I regard as a problem) 127.0.0.1 (Loopback no problem) The code: string strIP = null; IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); if (hostEntry.AddressList.Length > 0) { foreach (IPAddress ip in hostEntry.AddressList) { strIP = ip.ToString(); IPAddress tmpAddress; if (IPAddress.TryParse(strIP, out tmpAddress)) { socketListBox.Items.Add(strIP); } } } If my assumtion is correct how can I filter the items which cause phyical issues. Regards

      dotman1

      H Offline
      H Offline
      Hessam Jalali
      wrote on last edited by
      #2

      use Dns.Resolve instead og Dns.GetHostEntry method however the method is obsolete :( but it works fine good luck :)

      D O 2 Replies Last reply
      0
      • H Hessam Jalali

        use Dns.Resolve instead og Dns.GetHostEntry method however the method is obsolete :( but it works fine good luck :)

        D Offline
        D Offline
        dotman1
        wrote on last edited by
        #3

        :-D Thank you, this worked well. Regards

        dotman1

        1 Reply Last reply
        0
        • H Hessam Jalali

          use Dns.Resolve instead og Dns.GetHostEntry method however the method is obsolete :( but it works fine good luck :)

          O Offline
          O Offline
          originSH
          wrote on last edited by
          #4

          Yeah it works fine now but it'll probably get blasted in a future version of the framework. If a method is marked as obsolete it's a warning that you shouldn't use it if you want your code to be easily upgraded in the future.

          D 1 Reply Last reply
          0
          • O originSH

            Yeah it works fine now but it'll probably get blasted in a future version of the framework. If a method is marked as obsolete it's a warning that you shouldn't use it if you want your code to be easily upgraded in the future.

            D Offline
            D Offline
            dotman1
            wrote on last edited by
            #5

            I am aware of that, but until I can address the issue with the current framework this is a cleaner solution. Can you assist with this issue? Regards

            dotman1

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups