Deprecated: Creation of dynamic property Timber\Site::$pingback is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Site.php on line 180

Deprecated: Creation of dynamic property Timber\User::$name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/User.php on line 118

Deprecated: Creation of dynamic property Timber\Post::$has_disclaimer is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_lock is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_edit_last is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_meta_box_present is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_send_notification is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_modify_title_and_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_heading is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$onesignal_notification_custom_content is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_tipologia is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_attributi is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_in_evidenza_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_inviato_in_newsletter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_category is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_blz_affiliation_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_content_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_attributes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_primary_speciali is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_content_score is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskeywords is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_keywordsynonyms is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_estimated-reading-time-minutes is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$newsletter_subject is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_newsletter_subject is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$newsletter_summary is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_newsletter_summary is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_focuskw is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_metadesc is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_wpseo_linkdex is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_thumbnail_id is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$response_body is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_yoast_indexnow_last_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_e450fe9d52c9d879f7ee97b267c340b0 is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$_oembed_time_e450fe9d52c9d879f7ee97b267c340b0 is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_date_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$ping_status is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_password is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_name is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$to_ping is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$pinged is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_modified_gmt is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_content_filtered is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$guid is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$menu_order is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$post_mime_type is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$comment_count is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71

Deprecated: Creation of dynamic property Timber\Post::$filter is deprecated in /var/www/html/web/app/themes/ilsoftware/vendor/timber/timber/lib/Core.php on line 71
MyIP, un alias per trovare gli indirizzi IP su Linux e Windows | IlSoftware.it

MyIP, un alias per trovare gli indirizzi IP su Linux e Windows

Vediamo come creare un comando personalizzato myip su Linux e Windows, utile per ottenere velocemente le informazioni di rete fondamentali: hostname, IP pubblico (IPv4 e IPv6), indirizzi IP locali, gateway e DNS attivi.

In ambito sistemistico, la necessità di conoscere rapidamente gli indirizzi IP di un sistema è all’ordine del giorno. Sebbene esistano comandi standard, su Linux e Windows, come ip a, ifconfig, ipconfig e Get-NetIPAddress, potrebbe risultare molto utile disporre di uno script personalizzato, semplice da richiamare, che restituisca in pochi secondi una panoramica completa della connettività di rete: indirizzi IP locali e pubblici, gateway, DNS, IPv4 e IPv6. È qui che entra in gioco il comando myip, una funzione personalizzata che possiamo abilitare molto semplicemente sia in Linux che in Windows.

Obiettivo del comando myip: cos’è e come funziona

Il comando myip non esiste né su Linux né su Windows. Quanto sarebbe utile, invece, se si potesse disporre di un’istruzione, immediatamente utilizzabile, che espone tutti gli indirizzi IP in uso sulla macchina, in un formato chiaro, essenziale e soprattutto immediatamente comprensibile?

Vi sarà infatti capitato più volte di chiedervi: “qual è il mio indirizzo IP?”, “qual è l’indirizzo IP locale del sistema?” Un comando come myip fornisce subito tutte le informazioni sulla configurazione di rete che state cercando.

Nello specifico, vogliamo realizzare un comando myip capace di fornire, in una sola esecuzione, i dati che seguono:

  • Il nome host della macchina
  • L’indirizzo IP pubblico (IPv4 e IPv6)
  • Gli indirizzi IP locali delle sole interfacce di rete attive
  • I gateway di default
  • I server DNS in uso (con filtraggio dei DNS IPv6 automatici non utili)

Il tutto presentato in maniera ordinata, leggibile e immediatamente utile per troubleshooting, inventari di rete o configurazioni rapide.

MyIP su Linux: come aggiungere il comando con un alias

In Linux, una delle soluzioni più rapide e comode per eseguire comandi personalizzati come myip consiste nell’utilizzo degli alias. Un alias permette di associare una stringa semplice a uno script o a una serie di comandi più complessi, rendendo possibile richiamarli con una sola parola da qualsiasi posizione nel terminale.

Per visualizzare rapidamente gli indirizzi IP locali e pubblici, è possibile creare un alias myip che richiama uno script dedicato o una combinazione di comandi Bash, semplificando così l’accesso alle informazioni di rete essenziali senza dover digitare lunghi comandi ogni volta.

Nella finestra del terminale Linux incolliamo quanto segue:

alias myip='echo "Hostname: $(hostname)"; echo; echo "IP Pubblico (IPv4):"; curl -s https://ifconfig.me; echo; iface=$(ip -6 -o addr show scope global | awk "{print \$2}" | head -n1); if [ -n "$iface" ]; then echo "IP Pubblico (IPv6) [$iface]:"; curl -s https://ifconfig.me --interface "$iface"; else echo "IP Pubblico (IPv6): non disponibile"; fi; echo; echo "IP Locali:"; ip -o addr show | awk '\''$3 ~ /inet/ && $4 !~ /^127/ && $4 !~ /^::1/ && $4 !~ /^fe80/ {print $2 ": " $4}'\''; echo; echo "Gateway di default:"; ip route | awk '\''/default/ {print $3 " via " $5}'\''; echo; echo "DNS attivi:"; grep -E "^nameserver" /etc/resolv.conf | awk '\''{print $2}'\'''

Di primo acchito potrebbe sembrare complicato, in realtà si tratta di un comando che assegna all’alias myip una serie di operazioni, tra loro opportunamente concatenate.

Le operazioni svolte dall’alias myip su Linux

Per dare un’idea di ciò che fa il comando myip su Linux, la parte echo "Hostname: $(hostname)" serve per stampare il nome host della macchina, cioè il nome con cui il computer è identificato in rete locale.

Il comando curl -s https://ifconfig.me; richiama il servizio ifconfig.me per ottenere l’indirizzo IP pubblico del dispositivo in modo silenzioso (-s = silent), cioè senza output extra.

Le porzioni successive del comando estraggono le interfacce di rete presenti e rilevano tutti gli indirizzi IPv4 e IPv6 in uso. MyIP estrae anche il gateway e i server DNS configurati sulla macchina.

Digitando semplicemente myip nella finestra del terminale Linux, si ottiene in output perfettamente leggibile, simile al seguente.

myip alias su Linux

Rendere permanente l’alias myip sul sistema Linux

Per fare in modo che l’alias myip rimanga sempre utilizzabile, anche dopo il riavvio della macchina, basta digitare quanto segue. Al posto di alias_pubblicato_sopra va incollata l’istruzione completa che inizia per alias myip=.

echo "alias_pubblicato_sopra" >> ~/.bashrc
source ~/.bashrc

Come usare il comando myip su Windows

Potevamo esimerci dallo studiare una versione per Windows del comando myip? Per semplificare l’accesso rapido agli indirizzi IP locali, all’IP pubblico, al gateway e ai DNS attivi, è possibile creare un comando personalizzato utilizzando PowerShell.

Grazie a myip su Windows è possibile aggregare in modo automatico e immediato tutte le informazioni di rete più rilevanti, ottenendo un quadro completo e aggiornato in pochi secondi.

Aprite una finestra PowerShell (Windows+X, Terminale, Admin) quindi scrivete quanto segue:

New-Item -Path $PROFILE -ItemType File -Force
notepad $PROFILE

Nel file che si apre con il Blocco Note, aggiungete il contenuto dello script PowerShell pubblicato a questo indirizzo. Salvate quindi il file (CTRL+S) quindi chiudete e riaprite la finestra PowerShell.

Digitando myip e premendo il tasto INVIO, otterrete l’output con tutte le informazioni di rete di vostro interesse:

MyIP comando PowerShell per Windows

Si può ottenere lo stesso risultato, molto rapidamente, anche premendo la combinazione di tasti Windows+R quindi digitando quanto segue nel campo Apri:

powershell -noexit myip

Avvio comando myip su Windows con Esegui

Ti consigliamo anche

Link copiato negli appunti