SOL9 Sample: NetFwMgrIsPortAllowed

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * NetFwMgrIsPortAllowed.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2012/09/17

#include <sol\Locale.h>
#include <sol\com\ApartmentThreadedModel.h>
#include <sol\netfw\NetFwMgr.h>


void _tmain(int argc, const TCHAR* argv[])
{
  Locale locale;
  const TCHAR* encoding = _T("ISO-8859-1");
  if (argc == 2) {
    encoding = argv[1];
  }

  try {
    ApartmentThreadedModel model;  
    _tprintf(_T("<?xml version='1.0' encoding='%s' ?>\n"), encoding);
    _tprintf(_T("<NetFwApplication name='%s'>\n"), argv[0]);

    SOL::NetFwMgr netFwMgr;

    bool allowed    = false;
    bool restricted = false;
    {
      _bstr_t imageFile = "System"; 
      _bstr_t localAddr = "127.0.0.1";
      long    localPort = 80;  //HTTP
      NET_FW_IP_VERSION version = NET_FW_IP_VERSION_V4;
      NET_FW_IP_PROTOCOL protocol = NET_FW_IP_PROTOCOL_TCP;

      netFwMgr.displayIsPortAllowed(
            imageFile,    //ImageFileName
            version,    //NET_FW_IP_VERSION
            localPort,    //LocalPort WindowsMediaPlayer:2177. Netlogon:445
            localAddr,    //LocalAddress
            protocol,    //NET_FW_IP_PROTOCOL
            allowed,    //bool [out]
            restricted);  //bool [out]
    }

    {
      _bstr_t imageFile = "System"; 
      _bstr_t localAddr = "127.0.0.1";
      long    localPort = 443;  //SSTP
      NET_FW_IP_VERSION version = NET_FW_IP_VERSION_V4;
      NET_FW_IP_PROTOCOL protocol = NET_FW_IP_PROTOCOL_TCP;

      netFwMgr.displayIsPortAllowed(
            imageFile,    //ImageFileName
            version,    //NET_FW_IP_VERSION
            localPort,    //LocalPort WindowsMediaPlayer:2177. Netlogon:445
            localAddr,    //LocalAddress
            protocol,    //NET_FW_IP_PROTOCOL
            allowed,    //bool [out]
            restricted);  //bool [out]
    }

    {
      _bstr_t imageFile = "C:\\Windows\\system32\\snmptrap.exe"; //SNMPTRAP
      _bstr_t localAddr = "127.0.0.1";
      long    localPort = 162;  //SNMPTRAP 
      NET_FW_IP_VERSION version = NET_FW_IP_VERSION_V4;
      NET_FW_IP_PROTOCOL protocol = NET_FW_IP_PROTOCOL_UDP;

      netFwMgr.displayIsPortAllowed(
            imageFile,    //ImageFileName
            version,    //NET_FW_IP_VERSION
            localPort,    //LocalPort WindowsMediaPlayer:2177. Netlogon:445
            localAddr,    //LocalAddress
            protocol,    //NET_FW_IP_PROTOCOL
            allowed,    //bool [out]
            restricted);  //bool [out]
    }

    {
      _bstr_t imageFile = "C:\\Windows\\system32\\svchost.exe";
      _bstr_t localAddr = "127.0.0.1";
      long    localPort = 2177;  //Windows Media Player(qWave TCP) 
      NET_FW_IP_VERSION version = NET_FW_IP_VERSION_V4;
      NET_FW_IP_PROTOCOL protocol = NET_FW_IP_PROTOCOL_TCP;

      netFwMgr.displayIsPortAllowed(
            imageFile,    //ImageFileName
            version,    //NET_FW_IP_VERSION
            localPort,    //LocalPort WindowsMediaPlayer:2177. Netlogon:445
            localAddr,    //LocalAddress
            protocol,    //NET_FW_IP_PROTOCOL
            allowed,    //bool [out]
            restricted);  //bool [out]
    }
    _tprintf(_T("</NetFwApplication>\n"));

  } catch (Exception& ex) {
    ex.printf();  
  } catch (HRESULT hr) {
    _tprintf(_T("Exception: HRESULT=%x\n"), hr);
  }

}



Last modified: 2 May 2016

Copyright (c) 2016 Antillia.com ALL RIGHTS RESERVED.