annotate Test/RewritingTest/ParseAddress.cs @ 71:1169915705ab default tip

fix TopologyNode connect
author KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
date Sun, 06 Feb 2022 16:47:41 +0900
parents 9129c437b1a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 using System;
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 using System.Net;
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 class ParseAddress
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 private static void Main(string[] args)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 string IPaddress;
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 if (args.Length == 0)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 Console.WriteLine("Please enter an IP address.");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 Console.WriteLine("Usage: >cs_parse any IPv4 or IPv6 address.");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 Console.WriteLine("Example: >cs_parse 127.0.0.1");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 Console.WriteLine("Example: >cs_parse 0:0:0:0:0:0:0:1");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 return;
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 else
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 IPaddress = args[0];
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 // Get the list of the IPv6 addresses associated with the requested host.
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 Parse(IPaddress);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 // This method calls the IPAddress.Parse method to check the ipAddress
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 // input string. If the ipAddress argument represents a syntatically correct IPv4 or
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 // IPv6 address, the method displays the Parse output into quad-notation or
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 // colon-hexadecimal notation, respectively. Otherwise, it displays an
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 // error message.
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 private static void Parse(string ipAddress)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 try
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 // Create an instance of IPAddress for the specified address string (in
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 // dotted-quad, or colon-hexadecimal notation).
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 IPAddress address = IPAddress.Parse(ipAddress);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 // Display the address in standard notation.
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 Console.WriteLine("Parsing your input string: " + "\"" + ipAddress + "\"" + " produces this address (shown in its standard notation): "+ address.ToString());
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 catch(ArgumentNullException e)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 Console.WriteLine("ArgumentNullException caught!!!");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 Console.WriteLine("Source : " + e.Source);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 Console.WriteLine("Message : " + e.Message);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 catch(FormatException e)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 Console.WriteLine("FormatException caught!!!");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 Console.WriteLine("Source : " + e.Source);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 Console.WriteLine("Message : " + e.Message);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 catch(Exception e)
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 {
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 Console.WriteLine("Exception caught!!!");
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 Console.WriteLine("Source : " + e.Source);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 Console.WriteLine("Message : " + e.Message);
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }
1f7d4f168b89 socket test
riono <e165729@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }