Monday, October 12, 2015

Vérifier si un port est ouvert sur une machine distante

Il est parfois utile de savoir si un ordinateur ou un serveur est joignable sur un port précis ; cela sert à tester la santé d'un service (Apache, MySQL), à vérifier qu'un firewall est bien configuré, etc.

Telnet... pas si net !

Une première solution serait d'utiliser telnet pour ouvrir une session sur le port en question ; exemple ci-dessous avec le port 80 servant bien souvent au protocole HTTP :

$ telnet my.server.com 80
Problème : on entre alors en mode interactif et si l'on a pas l'habitude du protocole en question ou de l'outil telnet, sortir de ce mode peut se révéler être un vrai parcours du combattant !

Netcat forever ?

netcat (nc) propose une vérification quasi instantanée grâce aux options -zv ; on sait alors de suite si le port est ouvert et surtout, l'application nous rend de suite la main :

$ nc -zv my.server.com 80
Oui mais...

Depuis quelques temps, je me suis rendu compte que certaines implémentations de netcat (RedHat / CentOS à partir de la version 7) ne permettaient pas (ou plus) cela mais affichaient tout bonnement :

nc: invalid option -- 'z'
Ncat: Try `--help' or man(1) ncat for more information, usage options and help. QUITTING.
Quelle alternative ?

Une méthode universelle sous UNIX (y compris Linux, BSD et Mac OS X) est de passer par /dev/tcp et de jouer avec les sorties. Si l'on reprend notre précédent exemple cela donne :

$ 2>/dev/null >/dev/tcp/my.server.com/80
Ici pas de message puisque nous avons redirigé les sorties c'est donc la variable $? qui nous indique le bon fonctionnement de la manoeuvre ; cette dernière devant être égale à 0 en cas de réussite.

$ echo $?
0
On peut ensuite éventuellement utiliser les opérateurs && et || pour lancer un script uniquement si le port est respectivement ouvert ou fermé.

Exemple d'affichage d'un message si le port 80 est ouvert :

$ 2>/dev/null >/dev/tcp/my.server.com/80 && echo "Server on port 80 OK"
Exemple d'envoi de mail si le port 80 est fermé :

$ 2>/dev/null >/dev/tcp/my.server.com/80 || echo "Reboot or reconfigure your firewall" | mail -s "Server on port 80 KO" bob@example.com

http://bash.over-blog.com/2015/05/verifier-si-un-port-est-ouvert-sur-une-machine-distante.html

Installing PHP and the Oracle Instant Client for Linux and Windows

Installing PHP and the Oracle Instant Client for Linux and Windows


Configuration de PHP avec OCI8


High performance PHP applications with Oracle Database


Instant Client Downloads for Microsoft Windows (32-bit)

Call to undefined function oci-connect php oci8

php --ri oci8

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php-5.2.8\ext\php_
oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\php-5.2.8\ext\php_
pdo_oci8.dll' - %1 is not a valid Win32 application.
 in Unknown on line 0
Extension 'oci8' not present.

Aprés installation du client oracle oci8

php --ri oci8
PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) 'php_pdo_oc
i8.dll'  in Unknown on line 0

oci8

OCI8 Support => enabled
Version => 1.2.5
Revision => $Revision: 1.269.2.16.2.43 $
Active Persistent Connections => 0
Active Connections => 0
Temporary Lob support => enabled
Collections support => enabled

Directive => Local Value => Master Value
oci8.max_persistent => -1 => -1
oci8.persistent_timeout => -1 => -1
oci8.ping_interval => 60 => 60
oci8.privileged_connect => Off => Off
oci8.statement_cache_size => 20 => 20
oci8.default_prefetch => 10 => 10
oci8.old_oci_close_semantics => no value => no value

Thursday, October 1, 2015

Utlimate Cygwin

fixing-warning-unprotected-private-key-file-on-linux

If you are getting this error then you probably reset the permissions on your hidden .ssh directory in your user folder, and your keys aren’t going to work anymore. It’s very important that these files not be writable by just anybody with a login to the box, so openssh will give you an error if you try to use them.
The full error message:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0744 for '/home/geek/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /home/geek/.ssh/id_rsa
To fix this, you’ll need to reset the permissions back to default:
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub
If you are getting another error:
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/geek/.ssh/known_hosts).
This means that the permissions on that file are also set incorrectly, and can be adjusted with this:
sudo chmod 644 ~/.ssh/known_hosts
Finally, you may need to adjust the directory permissions as well:
sudo chmod 755 ~/.ssh

Source : http://www.howtogeek.com/168119/fixing-warning-unprotected-private-key-file-on-linux/