Visualizzazione post con etichetta mac. Mostra tutti i post
Visualizzazione post con etichetta mac. Mostra tutti i post

giovedì 3 febbraio 2011

Mysql: query record relativi a ieri e oggi

Per estrarre i record della tabella 'table' in cui il campo 'time_field' contenga una data compresa tra ieri e oggi, usare la query seguente:
SELECT * FROM table WHERE time_field >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)

Mysql: aggiungere il numero di record progressivo estratto da una query

Se abbiamo una query del tipo:

SELECT nome,cognome FROM utenti WHERE nome = 'Pippo'
Il cui risultato sara':

+-----+-------+
|nome |cognome|
+-----+-------+
|Pippo|xxxxx  |
+-----+-------+
|Pippo|YYYYY  |
+-----+-------+
2 rows in set (0.01 sec)


E desideriamo che ogni record sia preceduto dal numero progressivo di estrazione, come nell'esempio seguente:


+------+-----+-------+
|numero|nome |cognome|
+------+-----+-------+
|     1|Pippo|xxxxx  |
+------+-----+-------+
|     2|Pippo|YYYYY  |
+------+-----+-------+
2 rows in set (0.01 sec)


Dobbiamo prima eseguire una query per assegnare 0 ad una variabile (contatore) globale:
set @N = 0;
Il cui output sara':
Query OK, 0 rows affected (0.27 sec)

Seguita dalla query originale, aggiornata per l'utilizzo del contatore:
SELECT @N := @N +1 AS numero,nome,cognome FROM utenti WHERE nome = 'Pippo'

ATTENZIONE: ricordarsi di azzerare la variabile contatore prima di ogni query.

PHP: disabilitare (temporaneamente) i warning generati da uno script

Ci sono due possibilita:

  1. Inserire la riga seguente nel file di configurazione php.ini:
    display_errors = 0
  2. Inserire a inizio script la clausola:
    ini_set( "display_errors", 0);

Mysql: gestione degli arrotondamenti

A questo indirizzo trovate una presentazione delle funzioni matematiche di MySQL con una serie di interessanti commenti riguardanti le problematiche che si incontrano utilizzando le funzioni di arrotondamento:

http://dev.mysql.com/doc/refman/5.1/en/mathematical-functions.html

martedì 7 aprile 2009

La formula per risvegliare i (server) morti....


Un titolo cosi' avrebbe fatto furore nel periodo di Halloween.
Mi riferisco al Wake On Lan, una funzione che ci consente di accendere una macchina spenta tramite particolari pacchetti inviati in broadcast sulla rete.
La macchina che deve essere risvegliata deve avere installato il programma ethtool, se per caso non ci fosse gia' sara' sufficiente lanciare il seguente comando:
apt-get install ethtool

Verifichiamo la compatibilita' della scheda di rete con il protocollo di Wake On Lan:
root@dead:~# ethtool eth0 Settings for eth0: Supports Wake-on: g Wake-on: d Link detected: yes

La linea
Supports Wake-on: g

ci dice che il Wake On Lan e' supportato, pero' la linea
Wake-on: d

ci dice che la funzione e' disabilitata. Per attivarla lanciamo il seguente comando:

root@dead:~# ethtool -s eth0 wol g

Verifichiamo di nuovo la disponibilita' della funzione Wake On Lan:

root@dead:~# ethtool eth0
Settings for eth0:
Supports Wake-on: g
Wake-on: g
Link detected: yes
Ora non resta che conoscere il MAC address della scheda di rete del PC che vogliamo risvegliare. Avete due possibilita':
  1. Lanciare il comando ifconfig sul PC
  2. Utilizzare arp da un altro PC della stessa rete

IFCONFIG

Lanciate il comando seguente:
me@dead:~$ /sbin/ifconfig

otterrete qualcosa del genere:
eth0 Link encap:Ethernet HWaddr 00:0A:E6:F6:A3:F4
inet addr:192.168.1.80 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20a:e6ff:fef6:a3f4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2218390 errors:0 dropped:0 overruns:0 frame:0
TX packets:3098440 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1624008578 (1.5 GiB) TX bytes:1368310661 (1.2 GiB)
Interrupt:10 Base address:0xd400

In questo caso il MAC address (o Hardware Address) e' 00:0A:E6:F6:A3:F4
ARP
Su un'altra macchina della rete eseguite i seguenti comandi (supponiamo che la macchina di cui vogliamo conoscere il MAC address si chiami dead):

me@mystery:~$ ping -c 1 dead
me@mystery:~$ /usr/sbin/arp dead
Otterremo qualcosa del genere:
Address HWtype HWaddress Flags Mask Iface
dead ether 00:0A:E6:F6:A3:F4 C eth0

Anche in questo caso otteniamo il MAC address di dead ( 00:0A:E6:F6:A3:F4). Siamo quasi pronti e possiamo spegnere la macchina per testare il tutto.

Su un secondo PC della rete deve essere disponibile (in caso si tratti di una macchina Linux) uno dei seguenti programmi:
  1. etherwake
  2. wakeonlan
Ovviamente per installarli potete lanciare:
apt-get install wakeonlan
apt-get install etherwake
etherwake deve essere eseguito da root, wakeonline puo' essere eseguito anche da utenti senza privilegi.
Per risvegliare la macchina spenta usate uno dei seguenti comandi:
wakeonlan 00:0A:E6:F6:A3:F4
etherwake 00:0A:E6:F6:A3:F4

Poco dopo la macchina la cui scheda di rete e' caratterizzata dal MAC address usato, si accendera' e sara' disponibile in rete.

Se fate un giro su Google trovate client Wake On Lan anche per macchine windows.



martedì 4 novembre 2008

Gloobus e nautilus

Un interessante progetto (interessante per chi adora le chicche desktoppose) e' gloobus. Ricalcando Quicklook, un programma di Mac OS X, consente di sfogliare le immagini presenti in una directory in 3D come nella foto seguente:



Premendo SPAZIO viene visualizzata una preview ingrandita della foto corrente.


L'installazione e' molto semplice:
Scaricare i pacchetti gloobus e gloobus-preview dal sito: https://code.launchpad.net/gloobus/+download

cd /usr/local/src
tar xzvf /downloads/Gloobus-Preview-x.xx.tar.gz
tar xzvf /downloads/Gloobus-x.xxx.tar.gz
cd RELEASE
sudo ./install.sh


Se ricevete un errore relativo al file libSDL_gfx.so.4 potete installare la libreria mancante con il seguente comando, per poi rilanciare lo script install.sh:
sudo apt-get install libsdl-gfx1.2-4

L'autore del pacchetto vorrebbe fosse integrato in nautilus, per il momento possiamo farlo provvisoriamente utilizzando nautilus-actions:
sudo apt-get install nautilus actions

Selezionare dal menu di sistema System -> Preferences -> Nautilus Actions Configuration e aggiungere due azioni (nell'esempio coverflow e preview) configurate come nelle immagini seguenti





Far ripartire nautilus con il seguente comando:
killall nautilus

Ora lanciando nautilus e posizionandosi su una cartella contenente immagini, potete selezionare un file, cliccando con il tasto destro avrete a disposizione le voci coverflow e preview. La prima lancera' gloobus visualizzando l'anteprima di tutte le immagini presenti.

giovedì 24 aprile 2008

Come trovare MAC Address, indirizzo IP e nome del mio computer

Vedremo come farlo per sistemi:

  • Windows XP/2000
  • Mac
  • Linux
  • Windows Vista

Windows XP/2000
  • From the Start button select Run
  • In the box which appears type cmd and click OK
  • A new windows will appear - at the prompt type ipconfig /all
  • The MAC address will be referred to as the Physical Address and is made up of 12 characters e.g. 00-D1-AB-F2-G3-89
    You will have a separate MAC address for your wireless card and your Ethernet card. Make sure you use the correct one.
  • The IP address will be listed - if you are connected to the UWA network it should begin with 144.124.
  • The host name is your computer's name
Mac
  • From the Apple in the upper left hand corner choose System Preferences
  • Click on the Network icon
  • From the Show menu Select Airport (for Wireless) or Built in Ethernet (for Wired)
    • For the Built in Ethernet (for Wired) the MAC address will be at the top of the Ethernet tab as the Ethernet ID.
      The MAC address is the 12 character address e.g. 00:14:67:F0:56:A4
    • For the Airport (for Wireless) the MAC address will be at the top of the AirPort tab as the AirPort ID (or on the TCP/IP tab, again as the AirPort ID ). The MAC address is the 12 character address e.g. 00:14:67:F0:56:A4
  • The Current IP address (If there is one) will be under the TCP/IP tab for the AirPort and the Ethernet connections
  • To find your Computer Name go back to System Preferences and click on Sharing , your computer's name should be in the computer name box at the top of this window.

Linux
  • In a privileged terminal session type: ifconfig
  • This will show you a list of the network adapters installed. The MAC address is referred to here as the HWaddr
  • If you have a wireless card you will see more then one MAC Address, make sure you register the right MAC address.
  • To pick out your wireless MAC address type: iwconfig - your Wired one will be the other one

Windows Vista
  • Click the Start icon
  • Click All Programs
  • Click Accessories
  • Click Command Prompt
  • A new window will appear - at the prompt type ipconfig /all
  • The MAC address will be referred to as the Physical Address and is made up of 12 characters e.g. 00-D1-AB-F2-G3-89
    You will have a separate MAC address for your wireless card and your Ethernet card. Make sure you use the correct one.
  • The IP address will be listed - if you are connected to the UWA network it should begin with 144.124.
  • The host name is your computer's name

venerdì 11 aprile 2008

Wicd: patch per display MAC address su lista reti

11-04-2008: la patch di cui si parla in questo post e' stata inserita ufficialmente nella versione 1.5.0 di wicd. :-)

Ieri sera in seguito alla segnalazione sul blog di Alex, ho installato la versione 1.5.0 (testing) di wicd.
Come al solito wicd non ha tradito le attese. Almeno sulla rete di casa (WPA2 PSK) ha funzionato subito egregiamente.

L'unica cosa che mi ha fatto storcere il naso era il fatto che per vedere il MAC Address degli access point fosse necessario espanderne le informazioni (cosa abbastanza scomoda in presenza di molti access point)

Mi sono armato di grep e vi (alla faccia della programmazione visuale ;-) e ho patchato il programma gui.py per visualizzare i MAC Address direttamente nella lista delle reti.

Potete trovare la patch sul forum di wicd oppure qui.

Una volta scaricata la patch, eseguite i seguenti comandi:

sudo cp gui.patch.gz /opt/wicd
cd /opt/wicd
sudo gunzip /opt/wicd
sudo patch gui.py < gui.patch Alla prossima esecuzione, l'interfaccia utente vi mostrera' i MAC Address degli access point come nell'immagine seguente.