Some hint where could i start how nmap this manages ? Thank you.
man nmap
Also, I just relooked at your code and realized you are already using nmap for this. Why even bother making a script like this when you can just run:
nmap -sS -Pn -p 445 -T5 192.168.1.1
Or whatever. All you need is the -p 445, and it will tell you(with greater accuracy then your script) if the port is open, closed, or filtered(firewalled). Trust me, if you think of something pertaining to port or host scanning, nmap has probably thought of it already.