Ozzie.eu

Love to code, although it bugs me.

Test open network ports using Powershell

No comments
Most frequently when deploying new scenarios, the task of network connectivity validation has to be performed.
Commonly this is performed using a command line and issuing a “telnet” connection to the desired host on a given port. This is nice when you have a single machine with a couple of connections to be tested.
When the scenario involves tens of machines with different network connection requisites between each other, the telnet procedure is a very slow process, being the typical test cycle:
  1. Open command prompt.
  2. Issue telnet to a given host and port.
  3. On success, close window and return to step 1.
  4. On failure, wait for timeout.
  5. Authorize the network port that failed
  6. Repeat step 2.
  7. On success go to step 1.
This isn’t a time effective test cycle. The ideal test cycle would be:
  1. Open command prompt.
  2. Issue command or script to test all destination hosts on desired ports.
  3. Check status and authorize failed network traffic.
  4. Repeat step 2 and check for success.
The two most annoying things about telnet are that you need to close and open a new window on success and you have to wait for timeout on failure.
To surpass these annoyances, one can use this Powershell function “Test-Port”, available from the Microsoft Technet Script Center Repository.
The syntax of the base usage is really simple. To test conecctivity to this site:
Test-port -computer blog.ozzie.eu -port 80

To address the fact of the ever growing shared network resources to be tested, an Excel spreadsheet can be used to generate the test battery script. Here’s an example you can view and download:





Afterwards, you just copy/paste the powershell column to a .ps1 file. I’ve also included a regular command prompt test column.


HTH.

No comments :

Post a Comment

Python, Oracle and LOB objects

No comments
The Python programming language is my preferred tool to develop quick and (sometimes) dirty scripts to perform single shot data processing tasks.
Recently, one of these tasks  involved querying a table with a LOB column that stores XML strings. So the challenge was to read the LOB column and parse as string to dump the records to file.
My setup is Python 2.7 with the CxOracle 5.0.4 library. The first try I ran into the “LOB variable no longer valid after subsequent fetch” exception. According to the documentation this is because internally, Oracle uses LOB locators which are allocated based on the cursor array size. Thus, it is important that the data in the LOB object be manipulated before another internal fetch takes place. It also states that the safest way to do this is to use the cursor as an iterator.
Well, that’s all very nice, but I wouldn’t hang a cursor on a whole table, fetching the records one-by-one and processing the whole XML before going for another fetch. That’s not advisable on an OLTP database.
My solution and suggestion to other python users is to perform a two step fetch process:
  1. Fetch all relevant primary keys from the table;
  2. Fetch the LOB column one-by-one using the PK list from the previous step.
To whom it may interest, I also make available the ode snippet from the LOB reader function:
def executaQueryLOB(txtQuery):
    import cx_Oracle
 
    orcl = cx_Oracle.connect('yourConnectioString')
    curs = orcl.cursor()
    curs.execute(txtQuery)
    result=curs.fetchall()
    strLOB=result[0][0].read()
 
    orcl.close()
    
    return strLOB
HTH.

No comments :

Post a Comment

Cartão de Cidadão – APIs de Desenvolvimento

1 comment
De acordo com as notícias da actualidade, nomeadamente esta do Jornal de Negócios e esta da Semana Informática, as aplicações relacionados com os serviços da Administração Pública vão apostar fortemente na integração com o Cartão de Cidadão.
Esta aposta confirma-se com a publicação no Diário da República da Resolução do Conselho de Ministros nº.12/2012, de 7 de Fevereiro de 2012 que aprova o plano global estratégico de racionalização e redução de custos com as TIC na Administração Pública, apresentado pelo Grupo de Projeto para as Tecnologias de Informação e Comunicação (GPTIC).
Posto isto, é relevante fazer um levantamento do que existe actualmente que posa servir de base e acelerar o desenvolvimento da integrações do Cartão de Cidadão nas aplicações.
Numa pesquisa pouco exausta na Internet, aparecem os seguintes projectos:
O middlware do cartão é sempre necessário, de modo que na realidade apenas enumerei um projecto de terceiros que age com um wrapper .NET que expõe a API de interacção com o smart card.
Fica aqui o desafio de colocarem nos comentário a a esta mensagem algum projecto que conheçam ou usem e não esteja entre os referidos.

1 comment :

Post a Comment