Roteadores também “twittam” ;-)

Essa dica veio do Rodrigo Freitas, de um post no fórum do blog. Parece que também já havia sido postada no blog do Adilson (NetFinders). De qualquer forma, achei tão interessante que decidi publicar em forma de post no blog!

Segue:

Nao eh brincadeira…..

Os Cisco routers podem twittar…


# Instalacao no IOS:
#
# salve em um txt e renomeie para ciscotwitter.tcl coloque em flash:ciscotwitter.tcl
# configure um alias: alias exec ctw tclsh flash:ciscotwitter.tcl
# configure outro alias: alias exec ctw tclsh tftp://IP_DO_TFTP_SERVER/tcl/ciscotwitter.tcl
#
# execute com: ctw Message
# ctw "Mensagem com espaco"
#
# base64
#
namespace eval base64 {
set charset "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
# ----------------------------------------
# Dando o texto
proc encode {text} {
set encoded ""
set y 0
for {set i 0} {$i < [string length $text] } {incr i} {
binary scan [string index $text $i] c x
if { $x < 0 } {
set x [expr $x + 256 ]
}
set y [expr ( $y << 8 ) + $x]
if { [expr $i % 3 ] == 2} {
append encoded [string index $base64::charset [expr ( $y & 0xfc0000 ) >> 18 ]]
append encoded [string index $base64::charset [expr ( $y & 0x03f000 ) >> 12 ]]
append encoded [string index $base64::charset [expr ( $y & 0x000fc0 ) >> 6 ]]
append encoded [string index $base64::charset [expr ( $y & 0x00003f ) ]]
set y 0
}
}
if { [expr $i % 3 ] == 1 } {
set y [ expr $y << 4 ]
append encoded [string index $base64::charset [ expr ( $y & 0x000fc0 ) >> 6]]
append encoded [string index $base64::charset [ expr ( $y & 0x00003f ) ]]
append encoded "=="
}
if { [expr $i % 3 ] == 2 } {
set y [ expr $y << 2 ]
append encoded [string index $base64::charset [expr ( $y & 0x03f000 ) >> 12 ]]
append encoded [string index $base64::charset [expr ( $y & 0x000fc0 ) >> 6 ]]
append encoded [string index $base64::charset [expr ( $y & 0x00003f ) ]]
append encoded "="
}
return $encoded
}
#############################################################
# usuario_e_password
# --------------
proc encode_userpwd { username password } {
set text "$username:$password"
return [base64::encode $text]
}
#############################################################
GetBase64String
#
proc GetBase64String { username password } {
return [encode_userpwd $username $password]
}
#############################################################
# strlen
#
proc strlen string {
regsub -all . $string +1 string
expr 0$string
}

# Mensagem de Twitter
proc twittermsg { tw_server tw_auth tw_msg tw_len } {
set tw_totlen [expr $tw_len+7]
# abrindo um socket para enviar #
set sh [socket $tw_server 80]
puts -nonewline $sh "POST /statuses/update.xml HTTP/1.1\n"
puts -nonewline $sh "Authorization: Basic "
puts -nonewline $sh $tw_auth
puts -nonewline $sh "\n"
puts -nonewline $sh "User-Agent: ciscotwitter.tcl 0.3\n"
puts -nonewline $sh "Host: twitter.com\n"
puts -nonewline $sh "Accept: */*\n"
puts -nonewline $sh "Content-Length: "
puts -nonewline $sh $tw_totlen
puts -nonewline $sh "\n"
puts -nonewline $sh "Content-Type: application/x-www-form-urlencoded\n"
puts -nonewline $sh "\n"
puts -nonewline $sh "status="
puts -nonewline $sh $tw_msg
flush $sh
close $sh
return
}

# usando twitter API para enviar atualizacoes de status.
set twitterserver "www.twitter.com"
set username "my-twitter-user-name"
set password "my-twitter-password"
set basicauth [GetBase64String $username $password]
set twittertext [lindex $argv 0]
set twitterlen [strlen $twittertext]
if { $twitterlen > 0 && $twitterlen < 141 } then {
twittermsg $twitterserver $basicauth $twittertext $twitterlen
} else {
puts "Message to short or to long (1-140)"
}
#############################################################

Prepare IP + login + password (em um linux)

$ dig +short twitter.com
128.121.146.100
$ echo twitterlogin:twitterpassword | base64 -
dHdpdHRlcmxvZ2luOnR3aXR0ZXJwYXNzd29yZAo=

Na console do roteador:

rfreitas-router# copy tftp://192.168.0.1/tweet-policy.tcl flash:/tweet-policy.tcl
rfreitas-router(config)# event manager directory user policy "flash:/"
rfreitas-router(config)# event manager policy tweet-policy.tcl type user

rfreitas-router(config)# event manager environment _tweet_ip 128.121.146.100
rfreitas-router(config)# event manager environment _tweet_b64 dHdpdHRlcmxvZ2luOnR3aXR0ZXJwYXNzd29yZAo=

rfreitas-router# event manager run tweet-policy.tcl

rfreitas-router(config)#event manager applet tweetme
rfreitas-router(config-applet)# event timer watchdog time 300
rfreitas-router(config-applet)# action 1 policy tweet-policy.tcl

TCL Script na veia!!!

Abraços

Rodrigo Freitas.

routertweet.png

8 comentários

Pular para o formulário de comentário

  1. caramba !!!!

  2. Outra fonte de consulta, pode ser o blog do Adilson http://netfindersbrasil.blogspot.com/2010/07/ate-os-roteadores-estao-twittando.html

    que trouxe essa noticia no dia 13 de Julho …

    ou esse aqui http://www.packetlevel.ch/ que foi citado pelo próprio Adilson

  3. Eu ja tinha visto essa informação no blog do adilson, achei mt interessante tb…
    abs

  4. Bem interessante, show de bola.

  5. Puxa ! Como ninguem comentou nada no NetFinders, pensei que ninguem havia lido ou que nao tinham gostado ! rsrsrs ! Fico feliz em saber que muitos aqui haviam lido

    Agora, o merito por ter traduzido os comentarios do codigo eh todo do Rodrigo !

    Aproveito para reforcar o comentario do Deco sobre o http://www.packetlevel.ch/

    Vale a pena conhece-lo ! Tem muitas dicas legais !

    Abs,

  6. Legal, muito interessante. Imagino muitas coisas com essa facilidade!

  7. Bacana isso! Dá pra usar para tarefas de gerenciamento!

    Do jeito que as coisas vão, daqui a pouco estaremos vendo roteadores com orkut! rsrs

    Abraços a todos!

Deixe um comentário