#1 Le 06/01/2014, à 20:09
- lynn
[RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Bonjour,
Après des heures de recherches infructueuses, je pose une question sur la possibilité de créer un script qui permettrait d'afficher l'adresse IP externe avec vérification de celle ci toute les x minutes, dans la barre des tâches pour les utilisateurs de gnome-panel ou mate-panel.
J'ai vu ici qu'on pouvait créer des applets en python mais je n'ai aucune connaissance dans ce langage.
Dans le style, il existe giplet mais ça fonctionne pas sur les versions récentes d'Ubuntu...
Le but étant d'obtenir la même chose que sur cette image :
Y'a t-il quelqu'un qui aurait des infos, des idées, des liens ou des exemples pour créer ce script ?
Merci à vous.
Dernière modification par lynn (Le 20/05/2015, à 21:01)
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#2 Le 07/01/2014, à 00:21
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Je viens de tomber sur ce script qui date un peu mais ça ne fonctionne pas tel quel...
source : http://adesklets.sourceforge.net/desklets.html
#!/usr/bin/python
# coding=utf-8
"""
Copyright 2008 Hao Chi Kiang (woody_kiang <woodykiang@gmail.com>)
aexternip is a little desklet that shows your external IP address.
--------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
import adesklets, re, httplib
from os.path import dirname, join
class ipAddr_getter():
"""
Get external IP address
"""
def __init__(self, ip_check_url):
self.ip_check_url = ip_check_url
def get_ipAddr(self):
try:
url_splited = re.compile('/+').split(re.compile('^http://').sub('', self.ip_check_url))
host = url_splited[0]
path = ''
for tmp in url_splited[1:]:
path = '%s/%s' % (path, tmp)
connection = httplib.HTTPConnection(host)
if connection:
connection.request("GET", path)
response = connection.getresponse()
if response.reason == "OK":
ipAddr = re.compile('((\d{1,3}\.){3}\d{1,3})').split(response.read())[1]
else:
ipAddr = response.reason
connection.close()
except:
ipAddr = False
return ipAddr
class config(adesklets.ConfigFile):
"""
This is a configuration file of aexternip.py.
update_every : Updates the display every x seconds.
ip_check_url : URL to get your IP from.
"""
cfg_default = {
'font' : 'Vera',
'font_size' : 14,
'font_color' : '#EEEEEE',
'font_transparency' : 200,
'update_every' : 900,
'ip_check_url' : 'http://checkip.dyndns.org/'
}
def __init__(self, id, filename):
adesklets.ConfigFile.__init__(self, id, filename)
class Events(adesklets.Events_handler):
def __init__(self, basedir):
if len(basedir) != 0:
self.basedir = basedir
else:
self.basedir = '.'
adesklets.Events_handler.__init__(self)
def __del__(self):
adesklets.Events_handler.__init__(self)
def ready(self):
# Read configuration
self.config = config(adesklets.get_id(), join(self.basedir, 'config.txt'))
self.ip_check_url = self.config['ip_check_url']
self.font = "%s/%s" % (self.config['font'], self.config['font_size'])
self.font_color = [ eval('0x%s' % self.config['font_color'][1:3]),
eval('0x%s' % self.config['font_color'][3:5]),
eval('0x%s' % self.config['font_color'][5:]),
self.config['font_transparency']
]
self.delay = self.config['update_every']
#get external IP Address
self.ipgetter = ipAddr_getter(self.ip_check_url)
if self.ipgetter.get_ipAddr():
self.ipAddr = self.ipgetter.get_ipAddr()
else:
self.ipAddr = "No connection"
adesklets.window_set_transparency(1)
self.display()
adesklets.window_show()
def display(self):
adesklets.load_font(self.font)
adesklets.context_set_color (
self.font_color[0],
self.font_color[1],
self.font_color[2],
self.font_color[3]
)
adesklets.context_set_font(0)
self.text_x, self.text_y = adesklets.get_text_size(self.ipAddr)
adesklets.window_resize(self.text_x, self.text_y)
adesklets.images_reset_all() #Clean the window
adesklets.text_draw(0, 0, self.ipAddr)
adesklets.free_font(0)
def quit(self):
adesklets.Events_handler.__del__(self)
def alarm(self):
#Get external IP Address
if self.ipgetter.get_ipAddr():
self.ipAddr = self.ipgetter.get_ipAddr()
else:
self.ipAddr = "No connection"
#Redraw
self.block()
self.display()
self.unblock()
return self.delay
Events(dirname(__file__)).pause()
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#3 Le 07/01/2014, à 08:11
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Bonjour,
Quel est le message d'erreur ?
Hors ligne
#4 Le 07/01/2014, à 08:51
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
@ pingouinux
Voici le message d'erreur :
./aexternip.py
Do you want to (r)egister this desklet or to (t)est it? t
Now testing...
============================================================
If you do not see anything (or just an initial flicker
in the top left corner of your screen), try `--help',
and see the FAQ: `info adesklets'.
============================================================
Traceback (most recent call last):
File "./aexternip.py", line 152, in <module>
Events(dirname(__file__)).pause()
File "./aexternip.py", line 86, in __init__
adesklets.Events_handler.__init__(self)
File "/usr/lib/python2.7/dist-packages/adesklets/events_handler.py", line 157, in __init__
self.ready()
File "./aexternip.py", line 114, in ready
self.display()
File "./aexternip.py", line 119, in display
adesklets.load_font(self.font)
File "/usr/lib/python2.7/dist-packages/adesklets/commands.py", line 706, in load_font
return comm.out()
File "/usr/lib/python2.7/dist-packages/adesklets/commands_handler.py", line 103, in out
raise ADESKLETSError(4,message)
adesklets.error_handler.ADESKLETSError: adesklets command error - font 'Vera/14' could not be loaded
adesklets n'est plus dans les dépôts depuis un bon moment... ceci explique peut-être cela...?
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#5 Le 07/01/2014, à 09:35
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Tout ce que je peux dire, c'est qu'il ne trouve pas la police Vera/14 définie aux lignes 65-66 de aexternip.py. Tu peux éventuellement en essayer d'autres.
Hors ligne
#6 Le 07/01/2014, à 09:51
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
adesklet est bien présent ! J'ai trouvé un vieux paquet qui à bien voulu s'installé ( adesklets_0.6.1-5ubuntu1_amd64.deb )
Sinon, j'ai essayé avec "Arial" ou "Ubuntu" et ça me mets ça :
./aexternip.py
Do you want to (r)egister this desklet or to (t)est it? t
Now testing...
============================================================
If you do not see anything (or just an initial flicker
in the top left corner of your screen), try `--help',
and see the FAQ: `info adesklets'.
============================================================
Traceback (most recent call last):
File "./aexternip.py", line 25, in <module>
import adesklets, re, httplib
File "/usr/lib/python2.7/dist-packages/adesklets/__init__.py", line 43, in <module>
raise e
adesklets.error_handler.ADESKLETSError: adesklets interpreter initialization error - Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 14: reading configurations from ~/.fonts.conf is deprecated.
Exception AttributeError: AttributeError("'NoneType' object has no attribute 'kill'",) in <bound method _Communicator.__del__ of <adesklets.communicator._Communicator instance at 0x7ffa0f8a3ea8>> ignored
Que suis-je censée faire ?
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#7 Le 07/01/2014, à 10:01
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
J'ai trouvé un autre script :
#!/usr/bin/python
import os
import subprocess
import appindicator
import gtk
ICON = os.path.abspath("./images/icon.png")
def get_ip():
ip = subprocess.check_output('ifconfig |\
grep -o -P "inet addr:([^ ]*)" |\
grep -o -m 1 -P "[0-9.]+"', shell=True)
return ip.strip()
class IPIndicator:
def __init__(self):
self.ip = ""
self.ind = appindicator.Indicator("ip-indicator", ICON,
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()
refresh = gtk.MenuItem("Refresh")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)
return menu
def update(self):
"""
Update the IP address.
"""
ip = get_ip()
if ip != self.ip:
self.ip = ip
self.ind.set_label(ip)
def on_refresh(self, widget):
self.update()
if __name__ == "__main__":
i = IPIndicator()
gtk.main()
Par contre message d'erreur :
./ip.py
Traceback (most recent call last):
File "./ip.py", line 51, in <module>
i = IPIndicator()
File "./ip.py", line 22, in __init__
self.update()
File "./ip.py", line 41, in update
ip = get_ip()
File "./ip.py", line 12, in get_ip
grep -o -m 1 -P "[0-9.]+"', shell=True)
File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'ifconfig | grep -o -P "inet addr:([^ ]*)" | grep -o -m 1 -P "[0-9.]+"' returned non-zero exit status 1
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#8 Le 07/01/2014, à 10:13
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
C'est peut-être parce que le chemin de ifconfig n'est plus dans le PATH par défaut depuis "un certain temps" (c'est du moins comme ça chez moi).
Tu peux essayer de remplacer la ligne 10 de ip.py
ip = subprocess.check_output('ifconfig |\
par
ip = subprocess.check_output('/sbin/ifconfig |\
Hors ligne
#9 Le 07/01/2014, à 10:17
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Toujours pareil
./ip.py
Traceback (most recent call last):
File "./ip.py", line 51, in <module>
i = IPIndicator()
File "./ip.py", line 22, in __init__
self.update()
File "./ip.py", line 41, in update
ip = get_ip()
File "./ip.py", line 12, in get_ip
grep -o -m 1 -P "[0-9.]+"', shell=True)
File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '/sbin/ifconfig | grep -o -P "inet addr:([^ ]*)" | grep -o -m 1 -P "[0-9.]+"' returned non-zero exit status 1
Autrement, je viens de tester avec unity et ça fonctionne donc il doit bien y avoir un truc quelque part...?!
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#10 Le 07/01/2014, à 10:57
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
J'ai essayé ton ip.py. Avec la correction, je passe cette étape, et reste coincé dans gtk.main() (la dernière ligne du script).
Tu peux essayer cette ligne de commande dans un terminal
/sbin/ifconfig | grep -o -P "inet addr:([^ ]*)" | grep -o -m 1 -P "[0-9.]+"
Hors ligne
#11 Le 07/01/2014, à 10:59
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Cette ligne ne renvoie rien; retour au prompt.
lynn@saucy-64:/mnt/DOWNLOADS$ /sbin/ifconfig | grep -o -P "inet addr:([^ ]*)" | grep -o -m 1 -P "[0-9.]+"
lynn@saucy-64:/mnt/DOWNLOADS$
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#12 Le 07/01/2014, à 11:07
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Et celle-ci ?
/sbin/ifconfig
Hors ligne
#13 Le 07/01/2014, à 11:12
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
lynn@saucy-64:/mnt/DOWNLOADS$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr f4:6d:04:96:aa:29
inet adr:192.168.0.38 Bcast:192.168.0.255 Masque:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Packets reçus:6524267 erreurs:0 :0 overruns:0 frame:0
TX packets:7187157 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
Octets reçus:4354440444 (4.3 GB) Octets transmis:7291886417 (7.2 GB)
Interruption:20 Mémoire:f7f00000-f7f20000
lo Link encap:Boucle locale
inet adr:127.0.0.1 Masque:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
Packets reçus:327736 erreurs:0 :0 overruns:0 frame:0
TX packets:327736 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:0
Octets reçus:37714939 (37.7 MB) Octets transmis:37714939 (37.7 MB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet adr:x.x.x.x P-t-P:x.x.x.x Masque:255.255.255.224
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
Packets reçus:6348346 erreurs:0 :0 overruns:0 frame:0
TX packets:5595214 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:100
Octets reçus:3785111942 (3.7 GB) Octets transmis:4452414523 (4.4 GB)
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#14 Le 07/01/2014, à 11:24
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
L'explication vient de ce que tu dois être en version française, et que la sortie de ton ifconfig apparaît ainsi : inet adr:127.0.0.1, au lieu de inet addr:127.0.0.1 en version anglaise. Pour prévoir les deux, remplace la ligne 11 de ip.py
grep -o -P "inet addr:([^ ]*)" |\
par
grep -o -P "inet add?r:([^ ]*)" |\
Hors ligne
#15 Le 07/01/2014, à 11:32
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
La "bonne" nouvelle, c'est qu'il n'y a plus de message d'erreur par contre une fois lancé dans le terminal
lynn@saucy-64:/mnt/DOWNLOADS/unity-ip-indicator-master$ ./ip.py
et rien d'autre... rien ne s'affiche; Le systray reste vide ?!
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#16 Le 07/01/2014, à 11:37
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Là, je ne peux rien dire de plus, désolé…
Hors ligne
#17 Le 07/01/2014, à 11:39
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Petite précision, quand je lance la commande ./ip.py, je constate un mouvement dans le systray, comme une fenêtre mais sans rien dedans qui apparaît et disparaît aussitôt.
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#18 Le 07/01/2014, à 11:51
- pingouinux
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Effectivement, il apparaît dans mon "Indicator Applet" le premier IP de la sortie de ifconfig. Il ne disparaît que lorsque je fais un Ctrl+C dans la fenêtre de lancement du script.
Ajouté : Quand je clique-gauche sur cette étiquette, il apparaît l'élément de menu "Refresh"
Dernière modification par pingouinux (Le 07/01/2014, à 12:02)
Hors ligne
#19 Le 07/01/2014, à 19:35
- andso
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
bonjour,
j' ai ça, mais ça ne fonctionne plus sous xfce4.10 (xubuntu12.4), je suis en train d' investiguer
#!/bin/bash
#
# ------------------------------------------------------------------
# made by sputnick in da FreAkY lApPy lAb (c) 2009
# gilles.quenot <AT> gmail <DOT> com
# Idea from smecher.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
# (see http://www.gnu.org/licenses/gpl.html).
#
# version mofifiée par andso 2011 07 01
# ajout commentaire initialisation liaison
# utilise http://checkip.dyndns.org pour IP publique
# modification du message de lancement (mini howto )
# affiche les adresses IP en survolant l' icône de la zone de notification
# pas de confirmation pour l' arrêt
#
# ------------------------------------------------------------------
# ,,_
# o" )@
# ''''
# ------------------------------------------------------------------
#
# vim:ts=4:sw=4
#
#
# Version 0.2.2
#
#
# Script permettant de lancer un serveur web en dialog zenity a la volee dans le dossier courant.
# Il affiche les IP:PORT interne et externes qui seront disponibles.
#
# Si vous etes derriere un routeur, il faut le configurer pour que le port 8000
# soit forwarde vers votre adresse IP locale.
#
# Questions et infos : http://forum.ubuntu-fr.org/viewtopic.php?id=364489
#
# Prerequis:
# zenity
#
iface=eth0 # POUR LIAISON ETHERNET FILAIRE
#
# iface=wlan0 # pour liaison sans fil
## Votre interface reseau : iface=ra0, iface=wlan0 etc...
#
# ne plus modifier
# -----8<--------------------------------------------------------------------------------
# PUBLIC_IP_ADDR=$(wget -O - -q http://sputnick-area.net/ip) #
PUBLIC_IP_ADDR="$(wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1)"
PRIVATE_IP_ADDR=$(ifconfig $iface | awk '/inet/{gsub(" *inet add?r:","");print $1;exit}')
DIR=${1:-$PWD}
if nc -z -w2 localhost 8000; then
zenity --error --title="error:" --text="Le port localhost:8000 bind deja !\n\nSeeYa..."
exit 1
fi
zenity --question --text="Le répertoire \"$DIR\"
sera accessible dans un navigateur a l'adresse:
IP privée $PRIVATE_IP_ADDR :8000
IP publique $PUBLIC_IP_ADDR :8000 (pour vos amis)
Une icône se créera dans la zone de notification :
clic dessus pour Arrêter le serveur
Continuer?" --window-icon="/usr/share/pixmaps/siHTTP.png" || exit 0
python -m SimpleHTTPServer & pro=$!
while true; do
zenity --notification --window-icon="/usr/share/pixmaps/siHTTP.png" --text="Appuyer pour éteindre le serveur
IP privée $PRIVATE_IP_ADDR :8000
IP publique $PUBLIC_IP_ADDR :8000"
# public: $(wget -O - -q http://sputnick-area.net/ip):8000
# prive: $(ifconfig $iface | awk '/inet/{gsub(" *inet add?r:","");print $1;exit}'):8000
# if zenity --question --title="Confirmation?" --text="T'es sur ? Ca va trancher cherie !"; then
kill $pro
exit $?
# fi
done
IMPORTANT: Booster votre (X et K)ubuntu: http://forum.ubuntu-fr.org/viewtopic.php?id=241092 (pfou!...)
à essayer, et... demain debian? http://fr.wikipedia.org/wiki/Demain_les_chiens
demain les biens? mes biens biens? t' exagére ... la banque!
Hors ligne
#20 Le 07/01/2014, à 22:37
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Ca y'est, ça fonctionne !!
J'avais omis de mettre un truc... clic droit sur le tableau de bord, "ajouter au tableau de bord" et "applet de notification général".
J'ai modifié une partie du script pour mon usage; Chez moi l'ip attribuée au pc est fixe donc pas besoin de l'afficher puisque je la connais. Par contre quand on est derrière un vpn, c'est pratique de l'avoir affichée.
ip = subprocess.check_output('ifconfig |\
grep -o -P "inet addr:([^ ]*)" |\
grep -o -m 1 -P "[0-9.]+"', shell=True)
par ça
ip = subprocess.check_output('curl getip.fr/ip', shell=True)
N.B: applet de notification général
[edit 2]
sudo apt-get install indicator-application-gtk2 indicator-applet-complete
Dernière modification par lynn (Le 09/01/2014, à 21:22)
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#21 Le 07/01/2014, à 23:17
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Je passe le sujet en résolu. Merci pingouinux ainsi qu'à andso pour vos interventions.
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#22 Le 09/01/2014, à 21:35
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
J'ai fait un ajout dans le script pour vérifier et mettre à jour l'I.P dans l'applet. Ici le ping se fait toutes les 10 secondes.
#!/usr/bin/python
import os
import subprocess
import appindicator
import gtkICON = os.path.abspath("/home/$USER/bin/unity-ip-indicator-master/images/icon.png")
PING_FREQUENCY = 10 # seconds#def get_ip():
# ip = subprocess.check_output('ifconfig |\
# grep -o -P "inet add?r:([^ ]*)" |\
# grep -o -m 1 -P "[0-9.]+"', shell=True)
# return ip.strip()
def get_ip():
ip = subprocess.check_output('curl getip.fr/ip', shell=True)
return ip.strip()class IPIndicator:
def __init__(self):
self.ip = ""
self.ind = appindicator.Indicator("ip-indicator", ICON,
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()refresh = gtk.MenuItem("Refresh")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)return menu
def main(self):
gtk.main()def update(self):
gtk.timeout_add(PING_FREQUENCY * 1000, self.update)
"""
Update the IP address.
"""
ip = get_ip()
if ip != self.ip:
self.ip = ip
self.ind.set_label(ip)def on_refresh(self, widget):
self.update()if __name__ == "__main__":
i = IPIndicator()
gtk.main()
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#23 Le 20/05/2015, à 21:00
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Quelques modifications dans le script:
⇒ Nom du pays inscrit devant l'ip
⇒ Ajout de la fonction "quitter"
⇒ Traduction en français des menus
#!/usr/bin/env python
## A installer
## sudo apt-get install curl python-appindicator python-gtk2 indicator-applet-complete
##
import os
import subprocess
import appindicator
import gtk
import sysICON = os.path.abspath("/home/$USER/bin/unity-ip-indicator-master/images/icon.png") # Remplacer "$USER" par votre nom d'utilisateur et adapter le chemin pour charger "icon.png".
PING_FREQUENCY = 15 # secondsdef get_ip():
ip = subprocess.check_output("curl -s getip.fr/all | grep -E 'Country:|IP' | cut -d ':' -f2 | sort -r | awk -F: '{ printf \"%s \", $1}'| sed -e \"s/ / : /\"", shell=True)
return ip.strip()class IPIndicator:
def __init__(self):
self.ip = ""
self.ind = appindicator.Indicator("ip-indicator", ICON, \
appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()
refresh = gtk.MenuItem("Actualiser")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)
quit_item = gtk.MenuItem("Quitter")
quit_item.connect("activate", self.quit)
quit_item.show()
menu.append(quit_item)
return menu
def main(self):
gtk.main()def update(self):
gtk.timeout_add(PING_FREQUENCY * 1000, self.update)
ip = get_ip()
if ip != self.ip:
self.ip = ip
self.ind.set_label(ip)def on_refresh(self, widget):
self.update()def quit(self, widget):
sys.exit(0)if __name__ == "__main__":
ip = IPIndicator()
gtk.main()
Dernière modification par lynn (Le 24/05/2015, à 18:10)
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#24 Le 26/05/2015, à 03:55
- lynn
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
Modification du script
⇒ Ajout de l'icône du drapeau du pays de l'I.P en cours d'utilisation. Merci à soshi pour son aide : https://forum.ubuntu-fr.org/viewtopic.php?id=1843931
Il est nécessaire de posséder dans un dossier les icônes des pays voulus, par exemple, en les récupérant ici.
#!/usr/bin/env python
import os
import subprocess
import appindicator
import gtk
import sys
## A installer
## sudo apt-get install curl python-appindicator python-gtk2 indicator-applet-completePING_FREQUENCY = 15 # seconds
# fonction qui retrouve le nom du pays et l'IP
def get_ip():
ip = subprocess.check_output("curl -s getip.fr/all | grep -E 'Country:|IP' | cut -d ':' -f2 | sort -r | awk -F: '{ printf \"%s \", $1}'| sed -e \"s/ / : /\"", shell=True)
return ip.strip()# fonction qui retourne le code du pays
def get_country_code():
country = subprocess.check_output("curl -s getip.fr/countrycode", shell=True)
return country.strip()class IPIndicator:
def __init__(self):
self.ip = ""
self.ind = appindicator.Indicator(" ", " ", appindicator.CATEGORY_APPLICATION_STATUS)
self.ind.set_status(appindicator.STATUS_ACTIVE)
self.update()
self.ind.set_menu(self.setup_menu())
def setup_menu(self):
menu = gtk.Menu()
refresh = gtk.MenuItem("Actualiser")
refresh.connect("activate", self.on_refresh)
refresh.show()
menu.append(refresh)
quit_item = gtk.MenuItem("Quitter")
quit_item.connect("activate", self.quit)
quit_item.show()
menu.append(quit_item)
return menu
def main(self):
gtk.main()def update(self):
gtk.timeout_add(PING_FREQUENCY * 1000, self.update)
ip = get_ip()
if ip != self.ip: # lorsque l'ip change
self.ip = ip
self.ind.set_label(ip) # on met a jour le texte
self.ind.set_icon("/home/%s/unity-ip-indicator-master/images/png/"%(os.environ['USER']) + get_country_code() + ".png") # on met a jour l'icone
# Vérifier le format des icônes dans votre dossier ( png, jpg etc ) et modifier en conséquence cette partie ".png".def on_refresh(self, widget):
self.update()def quit(self, widget):
sys.exit(0)if __name__ == "__main__":
ip = IPIndicator()
gtk.main()
«C'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!»
Coluche
Hors ligne
#25 Le 28/05/2015, à 13:12
- andso
Re : [RESOLU] IP dans le systray ( Unity, Gnome-Panel, Mate-Panel...)
la même chose avec yad (fork de zenity)qui se loge dans le systray,
sans les drapeaux (bonne idée) et sans rafraichissement de l' adresse (one shot)
sur liaison filaire, (sinon modif du script, en dé/commentant les lignes iface)
#!/bin/bash
#
# ------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
# (see http://www.gnu.org/licenses/gpl.html).
#
# made by andso 2014 01 08
# uses yad
# https://launchpad.net/~webupd8team/+archive/y-ppa-manager
# http://code.google.com/p/yad/downloads/list
#
# Version 0.1.2
#
# Script showing internal and external IP adress in the systray.
#
# Questions et infos : http://forum.ubuntu-fr.org/viewtopic.php?id=1467201
#
#
iface=eth0 # POUR LIAISON ETHERNET FILAIRE
# iface=wlan0 # POUR LIAISON SANS FIL
## Votre interface reseau : iface=ra0, iface=wlan0 etc...
#
# ne plus modifier
# -----<--------------------------------------------------------------------------------
PUBLIC_IP_ADDR="$(wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1)"
PRIVATE_IP_ADDR=$(ifconfig $iface | awk '/inet/{gsub(" *inet add?r:","");print $1;exit}')
DIR=${1:-$PWD}
while true; do
yad --notification --image="/usr/share/pixmaps/siHTTP.png" --text="Appuyer pour éteindre
IP privée $PRIVATE_IP_ADDR
IP publique $PUBLIC_IP_ADDR"
kill $pro
exit $?
done
Dernière modification par andso (Le 30/05/2015, à 09:07)
IMPORTANT: Booster votre (X et K)ubuntu: http://forum.ubuntu-fr.org/viewtopic.php?id=241092 (pfou!...)
à essayer, et... demain debian? http://fr.wikipedia.org/wiki/Demain_les_chiens
demain les biens? mes biens biens? t' exagére ... la banque!
Hors ligne