Showing posts with label linux command. Show all posts
Showing posts with label linux command. Show all posts

4/26/2009

Tunnelling MySQL Over SSH On ubuntu

Context:
1 local PC
2 Remote PC IP:192.168.0.51
3 My SSH user name on remote PC is edwin

1 build a tunnel By ssh:
I will open a local TCP port 3333 for tunnelling mysql; The syntax of SSH is


ssh -L LOCAL_PORT:hostname:REMOTE_PORT USER_NAME@SERVER_NAME or IP_ADDRESS.

or with sshpass

sshpass -p 'YOUR_PASSWD' ssh -o StrictHostKeyChecking=no -L 3333:localhost:3306 USERNAME@REMORT_HOST -p 22

We're using localhost as the hostname because we are directly accessing the remote mysql server through ssh. You could also use this technique to port-forward through one ssh server to another server.

#ssh -L 3333:localhost:3306 edwin@192.168.0.51

2 Connect reomote mysql using mysql command

#mysql -u root -p -h 127.0.0.1 -P 3333

4/24/2009

Auto login script with expect on Ubuntu 9.04

1 install expect
sudo apt-get install expect
2 write shell script as the following:


#!/usr/bin/expect -f
# Expect script to supply root/admin password for remote ssh server
# and execute command.

# set Variables
set password "YOUR_PASSWORD"
set ipaddr "REMOTE_HOSTNAME"
set port 22

set timeout -1
# now connect to remote UNIX box (ipaddr) with given script to execute
spawn ssh $ipaddr -l root -p 22
match_max 100000
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
# send blank line (\r) to make sure we get back to gui
send -- "\r"
expect eof



3 save this file as edwin.ssh, and add X permission for it
4 use it

./edwin.ssh

11/20/2008

macchanger

macchanger 和 ifconfig [interface] hw ether [MAC] 的功能一樣, 可以變更網路卡卡號,
但並不是實體地修改卡號, 重開機後仍會回復, 嚴格說起來是可以設定網路卡卡號.
另外一個好用功能是可以查詢 vendor

查詢本機 eth0
# macchanger -s eth0
Current MAC: 00:02:b3:9b:b9:ba (Intel Corporation)

查詢 00:e0:4c 開頭是那一家做的
# macchanger -l | grep 00:e0:4c
7079 - 00:e0:4c - Realtek Semiconductor Corp.

列出 D-Link 的 MAC list
# macchanger --list=D-Link
Misc MACs:
Num MAC Vendor
--- --- ------

Wireless MACs:
Num MAC Vendor
--- --- ------
0012 - 00:05:5d - D-Link DWL-650, DWL-650H
0013 - 00:06:25 - Linksys WPC11 v2.5, D-Link DCF-650W, Linksys WPC11 v3
# macchanger --list=D-link
Misc MACs:
Num MAC Vendor
--- --- ------
1374 - 00:05:5d - D-link Systems, Inc.
3426 - 00:0d:88 - D-link Corporation
3863 - 00:0f:3d - D-link Corporation
5340 - 00:50:ba - D-link
5862 - 00:80:c8 - D-link Systems, Inc.

Wireless MACs:
Num MAC Vendor
--- --- ------
指定 keyword 大小寫有差, 資料檔 /usr/local/share/macchanger/OUI.list 的內容, 大小寫並沒有統一,
還是用 macchanger -l | grep -i keyword 比較實用