{"id":153,"date":"2010-02-28T22:52:37","date_gmt":"2010-02-28T20:52:37","guid":{"rendered":"http:\/\/www.fantascienza.com\/blog\/blackpig\/?p=153"},"modified":"2010-02-28T22:52:37","modified_gmt":"2010-02-28T20:52:37","slug":"sulle-differenze-tra-i-linguaggi-di-programmazione","status":"publish","type":"post","link":"https:\/\/luigirosa.com\/index.php\/2010\/02\/28\/sulle-differenze-tra-i-linguaggi-di-programmazione\/","title":{"rendered":"Sulle differenze tra i linguaggi di programmazione"},"content":{"rendered":"<p>Per varie ragioni (che non includono solamente il masochismo) voglio portare una procedurina di monitoraggio che ho scritto in <a href=\"http:\/\/www.perl.org\/\" target=\"_blank\" rel=\"noopener\">Perl<\/a> sotto Linux in ambiente Windows.<\/p>\n<p>Volendo usare un linguaggio script nativo in ambiente Windows per evitare di installare programmi di qualsiasi tipo sulla macchina da monitorare, decido di usare la <a href=\"http:\/\/it.wikipedia.org\/wiki\/Windows_PowerShell\" target=\"_blank\" rel=\"noopener\">PowerShell<\/a>.<\/p>\n<p><!--more-->Prima sorpresa: Microsoft distribuisce un (a suo dire) potente interprete di comandi e di script in cui l&#8217;esecuzione degli script \u00e8 bloccata per default. Vabb\u00e8, la cosa si risolve creando (o modificando) la chiave di registro <code>HKEY_Local_MachineSOFTWAREMicrosoftPowerShell1ShellIdsMicrosoft.PowershellExecutionPolicy<\/code> con valore <code>Unrestricted<\/code>. Benedetta Microsoft!<\/p>\n<p>Ok, gli script ora sono eseguibili.<\/p>\n<p>Veniamo allo scopo del test: creare uno script che prende una variabile data e la invia ad un server tramite HTTP POST (ovvero simulando la compilazione di un form) e recuperare la risposta del server.<\/p>\n<p>Svolgimento in PERL:<br \/>\n<code>$ua = LWP::UserAgent-&gt;new;<br \/>\n$req = (POST \"http:\/\/pippo\", [\"campo1\" =&gt; \"valore1\", \"campo2\" =&gt; \"valore2\"]);<br \/>\n$risposta = $ua-&gt;request($req);<\/code><\/p>\n<p>Svolgimento in PowerShell:<br \/>\n<code>[Reflection.Assembly]::LoadFile('C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Web.dll') | out-null<br \/>\n$postData = 'campo1=valore1&amp;campo2=valore2'<br \/>\n$buffer = [text.encoding]::ascii.getbytes($postData)<br \/>\n[net.httpWebRequest] $req = [net.webRequest]::create('http:\/\/pippo')<br \/>\n$req.method = \"POST\"<br \/>\n$req.ContentType = \"application\/x-www-form-urlencoded\"<br \/>\n$req.ContentLength = $buffer.length<br \/>\n$req.TimeOut = 5000<br \/>\n$reqst = $req.getRequestStream()<br \/>\n$reqst.write($buffer, 0, $buffer.length)<br \/>\n$reqst.flush()<br \/>\n$reqst.close()<br \/>\n[net.httpWebResponse] $res = $req.getResponse()<br \/>\n$resst = $res.getResponseStream()<br \/>\n$sr = new-object IO.StreamReader($resst)<br \/>\n$risposta = $sr.ReadToEnd()<\/code><\/p>\n<p>E per fortuna che \u00e8 una shell <em>power!!!<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Per varie ragioni (che non includono solamente il masochismo) voglio portare una procedurina di monitoraggio che ho scritto in Perl sotto Linux in ambiente Windows. Volendo usare un linguaggio script nativo in ambiente Windows per evitare di installare programmi di qualsiasi tipo sulla macchina da monitorare, decido di usare la PowerShell.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"local","activitypub_max_image_attachments":3,"footnotes":""},"categories":[11,12,20],"tags":[308,336,338,355,368,374],"class_list":["post-153","post","type-post","status-publish","format-standard","hentry","category-informatica","category-internet-informatica","category-programmazione","tag-microsoft","tag-open","tag-open-source","tag-perl","tag-powershell","tag-programmazione"],"_links":{"self":[{"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":0,"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"wp:attachment":[{"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/luigirosa.com\/index.php\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}