What is the best way of validating an IP Address?

后端 未结 10 845
时光取名叫无心
时光取名叫无心 2020-12-25 10:08

I have a method to validate a parameter IP Address. Being new to development as a whole I would like to know if there is a better way of doing this.



        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-25 10:45

    The framework provides the IPAddress class which in turn provides you the Parse and TryParse methods.

    // myAddress is a System.Net.IPAddress instance
    if (System.Net.IPAddress.TryParse(strIP , out myAddress)) 
        // IP is valid
    else
        // IP isn't valid
    

提交回复
热议问题