Windows 7和XP SP3(.Net 3.5 SP1)中的IPAddress.TryParse和IPv6不同结果 [英] IPAddress.TryParse and IPv6 different results in Windows 7 and XP SP3 (.Net 3.5 SP1)

查看:90
本文介绍了Windows 7和XP SP3(.Net 3.5 SP1)中的IPAddress.TryParse和IPv6不同结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我创建了一个扩展方法来验证字符串是否是使用IPAddress.TryParse的IPv6地址,然后我用这个字符串创建了一个测试用例
[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443 /

问题是如果我运行我的在XP SP3中测试测试通过但在Windows 7中测试失败。如果我删除字符串上的结尾斜杠,那么Windows 7和XP上的测试通过。

我的问题是我应该在两个平台上得到相同的行为吗?我的意思是如果有结束斜杠是错误的(顺便说一句,我复制了维基百科的地址)测试应该在两个平台上都失败,而不仅仅是在Windows 7中。

这是我的代码示例,以便你可以查看它。


Hi all, I created an extension method to validate if an string is an IPv6 address using IPAddress.TryParse, then i created a test case with this string
[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443/

The problem is that if I run my test in XP SP3 the test pass but in Windows 7 the test fails. If I delete the ending slash on the string then the test pass on Windows 7 and XP.

My issue here is that i should get the same behavior on both platforms right?, i mean if having the ending slash is wrong (BTW i copied the address from Wikipedia) the test should fail on both platforms not just in Windows 7.

Here is an example of my code so you can check it out.

public static bool IsIPAddressV6(this string source) {
			return (GetAddressFamily(source) == AddressFamily.InterNetworkV6);
		}
		private static AddressFamily GetAddressFamily(string source) {
			if(!string.IsNullOrEmpty(source)) {
				IPAddress tempValue;
				if(IPAddress.TryParse(source, out tempValue)) {
					return (tempValue.AddressFamily);
				}
			}
			return (AddressFamily.Unknown);
		}
		public void NetValidationsIsIPAddressV6Test() {
			//fails only in windows 7
			Assert.AreEqual(true, "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443/".IsIPAddressV6());
		}
		public void NetValidationsIsIPAddressV6NoSlashTest() {
			//pass on both windows and xp
			Assert.AreEqual(true, "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:443".IsIPAddressV6());

		}




推荐答案

可以你告诉我们你从IPAddress.Parse()回来的"AddressFamily"的价值是什么?
Can you tell us what is the value of "AddressFamily" that you are getting back from IPAddress.Parse() ?


这篇关于Windows 7和XP SP3(.Net 3.5 SP1)中的IPAddress.TryParse和IPv6不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆