.net - How to determine if a string is a valid IPv4 or IPv6 address in C#? -


I know that to validate IP address is regex to validate IP address.

I have seen similar questions for C and C ++, and they were sorted with functions that are not present in C #

.NET solution which I found Is the standard "ddd.ddd.ddd.ddd" form any suggestions?

You can use it to use and parse:

  IP address Trypers  

then check address family

returns System.Net.Sockets.AddressFamily.InterNetwork for IPv4 or System For .Net.Sockets.AddressFamily.InterNetworkV6 IPv6.

Edit: Some sample code changes in desired form:

  string input = "your IP address goes here"; IP address addresses; If (IP Address Traipers (Input, Out Address)) {Switch (Address AddressFamily) {Case Systems. met. Sockets. AddressFamily.Internetwork: // We have an IPv4 break; Case System.Net.Sockets.AddressFamily.InterNetworkV6: // is our IPv6 break; Default: // Umm ... Yes ... I need to take your red packet ... ... break; }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -