Telnet: ecco l’alternativa sfruttando la powershell
Se sei un amministratore di sistema Windows, conoscerai sicuramente l’importanza del comando Telnet nelle operazioni quotidiane di routine. Come si sa, tutte le versione di Windows sia Client che Server (a partire da Vista e versioni successive) vengono fornite con la funzionalità client Telnet disabilitata per impostazione predefinita.
Se si desidera testare la connettività o la raggiungibilità di alcuni computer, è necessario abilitare la funzionalità Windows telnet-client oppure cercare un comando alternativo a Telnet. In questo articolo, ti mostrerò come usare PowerShell, al posto della funzionalità client Telnet.
La sintassi di Telnet è abbastanza semplice come mostrato di seguito:
Telnet IndirizzoIP Porta
ES: Telnet 192.168.1.4 80
Ogni versione di Windows sia client che server è fornita di default con PowerShell già installata ed abilitato. In questo articolo creeremo un modulo di PowerShell che funzionerà esattamente come il comando Telnet tradizionale.
Dopo aver avviato la console di PowerShell e digitare il comando seguente per testare la connettività verso la porta 80 dell’IP 192.168.1.4:
Nell’immagine sopra riportata “True” indica che la connessione al server ha esito positivo. “False” al contrario indicherebbe che il PC non è in grado di connettersi al server sulla porta specificata.
Il comando precedente mostra se il server di destinazione è in ascolto di una porta specifica o meno.Se si desidera utilizzare il comando Telnet nella console di PowerShell esattamente come si fa nel prompt dei comandi, continuate a leggere l’articolo rimanente.
Creazione di uno script Powershell per il Telnet
Utilizzando la classe TcpClient .NET è possibile indicare a PowerShell di utilizzarla, al fine di creare un oggetto per aprire una connessione temporanea su un computer remoto.
In base al fatto che venga generato o meno un errore, è possibile sapere se la porta TCP è aperta o meno. In breve, questa funzione avvia il metodo Connect() sull’oggetto TcpClient su un computer remoto su una porta TCP.
Se il metodo Connect() non genera un errore, la variabile $status è impostata su Open. Se genera un errore, verrà rilevato e impostato su Chiuso/Filtrato. Infine, verrà creato un oggetto personalizzato con tutti i parametri necessari e messo sulla pipeline.
## Questo Script necessita della versione 3 di powershell in su functionTest-TcpPort($ComputerName,$TcpPort){try{## Create the TcpClient object and initiate a Connect method$socket = new-object Net.Sockets.TcpClient
$socket.Connect($ComputerName,$TcpPort)## The script will only get here if an error is not thrown by the above method$status = "Open"## Properly close the TCP connection once we're done$socket.Close()}catch{$status = 'Closed/Filtered'}finally{$obj = [PSCustomObject]@{
ComputerName = $ComputerName
TcpPort = $TcpPort
Status = $status}$obj}}## Usage$ComputerName = '192.168.1.4'$TcpPort = '80'Test-TcpPort$ComputerName$TcpPort
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.