Archive

Articles taggués ‘commands’

How to find out Router MAC address

28/05/2023 Aucun commentaire

Source: nixCraft

MAC is acronym for for Media Access Control address. It is a unique identifier attached to almost most all networking equipment such as Routers, Ethernet cards and other devices.

If you do not have access to router admin interface (via telnet or webbased), use following method to find out router MAC address.

You need to use arp command (available on both Windows, Linux/Unixish systems).

arp manipulates the kernel’s ARP cache in various ways. The primary options are clearing an address mapping entry and manually setting up one. For debugging purposes, the arp program also allows a complete dump of the ARP cache.

arp shows the entries of the specified hosts. If the hostname parameter is not used, all entries will be displayed.

Task: Find out router Mac Address

To find out your router MAC address, use arp command as follows:

$ /usr/sbin/arp -a
OR
$ arp -a
Output:

router (192.168.1.254) at 00:08:5C:00:00:01 [ether] on eth0
fbsd6 (192.168.1.16) at 00:0F:EA:91:04:07 [ether] on eth0

In above example 00:08:5C:00:00:01 is MAC address of my router. If you cannot find MAC address then just ping to your router once (my router had 192.168.1.254 IP)
$ ping 192.168.1.254
And then run (type arp -a) above arp command again. If you have telnet access to router then you can just telnet into router and find out MAC address:
$ telnet 192.168.1.254

Output:

Welcome to nixCraft Router!
Login: admin
Password:

Once logged in type ifconfig command:

$ ifconfig br0

Output:

br0             Link encap:Ethernet  HWaddr 00:08:5C:00:00:01
        inet addr:192.168.1.254  Bcast:192.168.1.255  Mask:255.255.255.0
        UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
        RX packets:48574 errors:0 dropped:0 overruns:0 frame:0
        TX packets:61329 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:9146189 (8.7 MiB)  TX bytes:74456679 (71.0 MiB)

Please note that your interface name (br0) could be different. You can also use ifconfig -a command.

Windows XP/NT/2003 find out Router Mac address

If you are using Microsoft Windows XP then you need to open MS-DOS shell prompt first. Click on Start > Run > Type cmd command followed by ENTER key. Then at C:\> prompt, type arp command as follows:

C:\> arp -a

Categories: Réseau Tags: ,

Afficher une image dans un terminal

26/05/2023 Aucun commentaire

Source: korben.info

Si vous cherchez un utilitaire et une bibliothèque pour vos projets qui permette d’afficher dans un terminal une image en utilisant du code ANSI, j’ai ce qu’il vous faut. Ça s’appelle Picture- et pour l’ c’est très simple. Il vous faudra npm, donc sous pour un petit npm, il faut taper :

sudo apt-get install npm

Ensuite pour installer la bibliothèque Picture-tube, il faut faire :

sudo npm install picture-tube

Si seul l’outil en vous intéresse, ajoutez le paramètre -g

sudo npm install -g picture-tube

Ensuite, pour convertir une image, un petit

picture-tube monimage.jpg

dans le terminal et taaadaaa

 

zelda

Après, pour utiliser la bibliothèque, voici un exemple de code :

var pictureTube = require('picture-tube')
var tube = pictureTube();
tube.pipe(process.stdout);
var fs = require('fs');
fs.createReadStream('robot.png').pipe(tube);

Pour tout le reste, c’est par ici.

Categories: Logiciel Tags: , ,

Useful Mac bash terminal shortcuts

19/05/2023 Aucun commentaire

Open directory in finder

open .

Pbcopy and pbpaste

grep 'searching for' hugeFile.txt | pbcopy
pbpaste | sed 's/ / /g'

mdfind command is the spotlight search from command line

say "Hello there"

The say command invokes the system text-to-speech capabilities.

cd -

Will restore the previous directory you were in. Very handy if you accidentally type cd and flip to home.

And some usefull aliases

alias ..="cd .." alias ...="cd .. ; cd .."
alias ls="ls -G" # list alias la="ls -Ga" # list all, includes dot files alias ll="ls -Gl" # long list, excludes dot files alias lla="ls -Gla" # long list all, includes dot files
alias stfu="osascript -e 'set volume output muted true'" alias pumpit="osascript -e 'set volume 10'"
alias ips="ifconfig -a | perl -nle'/(d .d .d .d )/ && print $1'" alias myip="dig  short myip.opendns.com @resolver1.opendns.com"

Bash Keyboard Shortcuts

Moving the cursor:

  Ctrl   a   Go to the beginning of the line (Home)
  Ctrl   e   Go to the End of the line (End)
  Hold the Option key option and click on the current line = Jump Backwards

  Ctrl   p   Previous command (Up arrow)
  Ctrl   n   Next command (Down arrow)
  Hold the Option key option and click on a previous line = Jump upwards

  Ctrl   f   Forward one character
  Ctrl   b   Backward one character
   Alt   b   Back (left) one word      or use Option Right-Arrow
   Alt   f   Forward (right) one word  or use Option Left-Arrow

  Ctrl   xx  Toggle between the start of line and current cursor position

Editing:

 Ctrl   L   Clear the Screen, similar to the clear command

  Alt   Del Delete the Word before the cursor.
  Alt   d   Delete the Word after the cursor.
 Ctrl   d   Delete character under the cursor
 Ctrl   h   Delete character before the cursor (backspace)

 Ctrl   w   Cut the Word before the cursor to the clipboard.
 Ctrl   k   Cut the Line after the cursor to the clipboard.
 Ctrl   u   Cut/delete the Line before the cursor position.

  Alt   t   Swap current word with previous
 Ctrl   t   Swap the last two characters before the cursor (typo).
 Esc    t   Swap the last two words before the cursor.

 ctrl   y   Paste the last thing to be cut (yank)
  Alt   u   UPPER capitalize every character from the cursor to the end of the current word.
  Alt   l   Lower the case of every character from the cursor to the end of the current word.
  Alt   c   Capitalize the character under the cursor and move to the end of the word.
  Alt   r   Cancel the changes and put back the line as it was in the history (revert).
 ctrl   _   Undo
 
  TAB       Tab completion for file/directory names

For example, to move to a directory ‘sample1’; Type cd sam ; then press TAB and ENTER.
type just enough characters to uniquely identify the directory you wish to open.

Special keys: Tab, Backspace, Enter, Esc

Text Terminals send characters (bytes), not key strokes.
Special keys such as Tab, Backspace, Enter and Esc are encoded as control characters.
Control characters are not printable, they display in the terminal as ^ and are intended to have an effect on applications.

Ctrl I = Tab
Ctrl J = Newline
Ctrl M = Enter
Ctrl [ = Escape

Many terminals will also send control characters for keys in the digit row:

Ctrl 2 → ^@
Ctrl 3 → ^[ Escape
Ctrl 4 → ^
Ctrl 5 → ^]
Ctrl 6 → ^^
Ctrl 7 → ^_ Undo
Ctrl 8 → ^? Backward-delete-char

Ctrl v tells the terminal to not interpret the following character, so Ctrl v Ctrl-I will display a tab character,
similarly Ctrl v ENTER will display the escape sequence for the Enter key: ^M

History:

  Ctrl   r   Recall the last command including the specified character(s)
             searches the command history as you type.
             Equivalent to : vim ~/.bash_history. 
  Ctrl   p   Previous command in history (i.e. walk back through the command history)
  Ctrl   n   Next command in history (i.e. walk forward through the command history)
   Alt   .   Use the last word of the previous command
  Ctrl   s   Go back to the next most recent command.
            (beware to not execute it from a terminal because this will also launch its XOFF).
  Ctrl   o   Execute the command found via Ctrl r or Ctrl s
  Ctrl   g   Escape from history searching mode

Process control:

 Ctrl   C   Interrupt/Kill whatever you are running (SIGINT)
 Ctrl   l   Clear the screen
 Ctrl   s   Stop output to the screen (for long running verbose commands)
 Ctrl   q   Allow output to the screen (if previously stopped using command above)
 Ctrl   D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
 Ctrl   Z   Send the signal SIGTSTP to the current task, which suspends it.
            To return to it later enter fg 'process name' (foreground).

To use the Alt Key Shortcuts in OS X – Open Terminal Preferences | Settings Tab | Keyboard | Tick “Use option as meta key”

Emacs mode vs Vi Mode

All the above assume that bash is running in the default Emacs setting, if you prefer this can be switched to Vi shortcuts instead.

Set Vi Mode in bash:

$ set -o vi

Set Emacs Mode in bash:

$ set -o emacs

Source: @coderwall and ss64.com

Categories: Système Tags: , , ,

Tree en une ligne de commande (sed)

16/05/2023 Aucun commentaire

Source: didier.misson.net

Mais que fait cette commande ?

Il suffit d’essayer en ligne de commande…

Non, ce n’est pas risqué.

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'

Cette commande liste vos dossiers en arborescence, sous forme d’un arbre.

C’est plutôt pour le fun, et pour utiliser SED, car on ne va pas retaper cette longue commande à chaque fois !

Voyez donc ce billet comme un exercice, un exemple de ce qu’on peut faire en ligne de commande avec SED, et pas comme un « truc et astuce ».

J’ai ensuite voulu comprendre comment cette commande fonctionnait.

On y retrouve des commandes assez classiques en Linux : ls, grep et sed.

Lire la suite…

Categories: Système Tags: ,

Synchronizing folders with rsync

13/05/2023 Comments off

Source: Juan Valencia’s website

In this post I cover the basics of rsync, in preparation for a subsequent post that will cover backups and it’s use in conjunction with cronjobs to automatize the backup process. From the copying and synchronization of local files and folders, to it’s use for transfer information among computers. Itsuse as a daemon when SSH is unavailable was moved to it’s own section.

Topics
The basics of rsync
Copying local files and folders
Dealing with whitespace and rare characters
Update the contents of a folder
Synchronizing two folders with rsync
Compressing the files while transferring them
Transferring files between two remote systems
Excluding files and directories
Running rsync as a daemon (moved to it’s own section)
Some additional rsync parameters
Footnotes

The basics of rsync

rsync is a very versatile copying and backup tool that is included by default in almost every Linux distribution. It can be used as an advanced copying tool, allowing us to copy files both locally and remotely. It can also be used as a backup tool. It supports the creation of incremental backups.

rsync counts with a famous delta-transfer algorithm that allows us to transfer new files as well as recent changes to existent files, while ignoring unchanged files. Additionally to this, the behavior ofrsync can be throughly customized, helping us to automatize backups, it can also be run as a daemon to turn the computer into a host and allow rsync clients connect to it.

Besides the copying of local files and folders, rsync allow us to copy over SSH (Secure Shell), RSH (Remote Shell) and it can be run as a daemon in a computer and allow other computers to connect to it, when rsync is run as a daemon it listens to the port TCP 873.

When we use rsync as a daemon or when we use RSH, the data that is send between computers travels unencrypted, so, if you are transferring files between two computers in the same local network, this is useful, but this shouldn’t be used to transfer files over insecure networks, such as the Internet. For this purpose SSH is the way to go.

This is the main reason why I favor the use of SSH for my transfers, besides, since SSH is secure, many servers have the SSH daemon available. But the use of rsync as a daemon for transfers over fast connections, as is usually the case in a local network, is useful. I don’t have the RSH daemon running in my computers so you may find me a bit biased about SSH in the examples. The examples covering the transfer of files between two computers use SSH as the medium of transport, but in a separate post I cover the use of rsync as a daemon.

Lire la suite…

Categories: Réseau, Système Tags: , ,