locked
How to check the ports has been enabled or not through samples of code?? RRS feed

  • Question

  • HI..

    I wanted to certain pieces of code to check wether the ports has been enabled or not in my machine by running few samples.. Could anyone provide me the samples..

    Thursday, November 15, 2012 9:06 AM

Answers

  • HI

     You can use some code like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Net.NetworkInformation;
    using System.Collections;
    namespace ConsoleApplication1 {
        static class Program {
            //List used tcp port
            static void ListAvailableTCPPort(ref ArrayList usedPort) {
                IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
                TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
                IEnumerator myEnum = tcpConnInfoArray.GetEnumerator();
                while (myEnum.MoveNext()) {
                    TcpConnectionInformation TCPInfo = (TcpConnectionInformation)myEnum.Current;
                    Console.WriteLine("Port {0} {1} {2} ", TCPInfo.LocalEndPoint, TCPInfo.RemoteEndPoint, TCPInfo.State);
                    usedPort.Add(TCPInfo.LocalEndPoint.Port);
                }
            }
            public static void Main(){
                ArrayList usedPorts = new ArrayList();
                ListAvailableTCPPort(ref usedPorts);
                Console.ReadKey();
            }
        }
    }

    Aslo you can use this way: use command line:

    C:\Users\hari>telnet 1d6d6f26c0184f6c8ef29e1cf40a87e7.cloudapp.net 80

    For details please refer to:

    IP Range for Windows Azure Platform, Identifying connectivity issues

    Hope it helpful.




    • Edited by Dino He Thursday, November 22, 2012 1:17 PM Fix some typo
    • Marked as answer by Dino He Thursday, November 22, 2012 1:17 PM
    Friday, November 16, 2012 3:15 AM

All replies

  • I have checked the port 1433 by connecting the SQl Azure from on- premise Management portal..

    I have checked the TCP 80 bye putting the following code :

    ServiceHost

    sh = newServiceHost(typeof(CalcServiceReference.Service1Client));

                sh.AddServiceEndpoint(

                  

    typeof(CalcServiceReference .IService1), newNetTcpBinding(),

                  

    "net.tcp://localhost:9358/solver");

               

    // http://localhost:57785/Service1.svc


                        

                sh.AddServiceEndpoint(

    typeof(CalcServiceReference.IService1), newNetTcpRelayBinding(),

                  

    ServiceBusEnvironment.CreateServiceUri("sb", "mysampleservicebus", "Service1"))

                    .Behaviors.Add(

    newTransportClientEndpointBehavior


                    {

                        TokenProvider =

    TokenProvider.CreateSharedSecretTokenProvider("owner", "NliskWommo4/ThlASyVH504OymV1NUq7YXDSrVDzZWI=")

                    });

                sh.Open();

               

    Console.WriteLine("Press ENTER to close");

               

    Console.ReadLine();

                sh.Close();

    Need to check for the rest of the ports..

    Thursday, November 15, 2012 9:14 AM
  • HI

     You can use some code like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Net.NetworkInformation;
    using System.Collections;
    namespace ConsoleApplication1 {
        static class Program {
            //List used tcp port
            static void ListAvailableTCPPort(ref ArrayList usedPort) {
                IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
                TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
                IEnumerator myEnum = tcpConnInfoArray.GetEnumerator();
                while (myEnum.MoveNext()) {
                    TcpConnectionInformation TCPInfo = (TcpConnectionInformation)myEnum.Current;
                    Console.WriteLine("Port {0} {1} {2} ", TCPInfo.LocalEndPoint, TCPInfo.RemoteEndPoint, TCPInfo.State);
                    usedPort.Add(TCPInfo.LocalEndPoint.Port);
                }
            }
            public static void Main(){
                ArrayList usedPorts = new ArrayList();
                ListAvailableTCPPort(ref usedPorts);
                Console.ReadKey();
            }
        }
    }

    Aslo you can use this way: use command line:

    C:\Users\hari>telnet 1d6d6f26c0184f6c8ef29e1cf40a87e7.cloudapp.net 80

    For details please refer to:

    IP Range for Windows Azure Platform, Identifying connectivity issues

    Hope it helpful.




    • Edited by Dino He Thursday, November 22, 2012 1:17 PM Fix some typo
    • Marked as answer by Dino He Thursday, November 22, 2012 1:17 PM
    Friday, November 16, 2012 3:15 AM