API Reference

Version 2 (Alan McGovern, 04/16/2009 10:06 PM)

1 1
h1. API Reference
2 1
3 2 Alan McGovern
<pre>
4 1
class NatTest
5 1
	{
6 1
		public static void Main(string[] args)
7 1
		{
8 1
			new NatTest ();
9 1
		}
10 1
		
11 1
		public NatTest ()
12 1
		{
13 1
			NatUtility.DeviceFound += DeviceFound;
14 1
			NatUtility.DeviceLost += DeviceLost;
15 1
			
16 1
			NatUtility.StartDiscovery ();
17 1
            Console.ReadLine();
18 1
		}
19 1
20 1
        private void DeviceFound(object sender, DeviceEventArgs args)
21 1
        {
22 1
            INatDevice device = args.Device;
23 1
         
24 1
            // Create a mapping to forward external port 3000 to local port 1500
25 1
            device.CreatePortMap(new Mapping(Protocol.Tcp, 1500, 3000));
26 1
27 1
            // Retrieve the details for the port map for external port 3000
28 1
            Mapping m = device.GetSpecificMapping(Protocol.Tcp, 3000);
29 1
30 1
            // Get all the port mappings on the device and delete them
31 1
            foreach (Mapping mp in device.GetAllMappings())
32 1
                device.DeletePortMap(mp);
33 1
34 1
            // Get the external IP address
35 1
            IPAddress externalIP = device.GetExternalIP();
36 1
        }
37 1
		
38 1
		private void DeviceLost (object sender, DeviceEventArgs args)
39 1
		{
40 1
			INatDevice device = args.Device;
41 1
			
42 1
			Console.WriteLine ("Device Lost");
43 1
			Console.WriteLine ("Type: {0}", device.GetType().Name);
44 1
		}
45 1
	}
46 2 Alan McGovern
</pre>