Wednesday, March 30, 2011

Set up Windows, Figure out how to list network devices in Linux

On Monday, I met with Victor and leaned that there are 2 different ways to write the API. I'm going to use Victor's ether_shell way.

Made a new to-do list:

I. Windows set things up
II. Linux: Find how to list all the network card names
III. to-do 2/4: Windows/MacOS: Find code in Wireshark that a) communicates to the ethernet, b) gets the MAC addresses in those operating systems
IV. to-do 3/4: Read POSIX socket API document


I. Windows: set things up to test on it
  1. Install Windows XP virtual machine on my computer's VM Player (victor gave me its iso)
  2. Install Ruby http://rubyinstaller.org/
    • check "add ruby executables to your PATH"
    • check "associate .rb and .rbw files with this ruby installation"
  3. Install Git http://code.google.com/p/msysgit/downloads/list
    • select "rub git from the Windows command prompt"
    • select "checkout windows-style, commit unix-style line endings"
  4. Install wireshark
    • Ignore the popup that's about enabling promiscuous mode
  5. Download my github ethernet project (that is currently is a copy/paste of Victor's ether_shell), I just want to see if the rspec can run.
    • No. When I ran rspec ethernet_spec.rb I got:
      sh.exe": rspec: command not found
      So I did, like on Linux, gem install rspec, and then rspec worked!
  6. I tried to replicate pinging Wireshark based on this blog entry, but at the rake install step, I got an error as expected, since I haven't written anything that makes things work on Windows yet!
    rake aborted!
    undefined method `write' for #<Syck::Emitter:0x11efad0>
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/emitter.rb:17:in `end_document'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/emitter.rb:17:in `visit_Psych_Nodes_Document'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/visitor.rb:10:in `accept'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/emitter.rb:10:in `block in visit_Psych_Nodes_Stream'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/emitter.rb:10:in `each'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/emitter.rb:10:in `visit_Psych_Nodes_Stream'
    c:/Ruby192/lib/ruby/1.9.1/psych/visitors/visitor.rb:11:in `accept'
    c:/Ruby192/lib/ruby/1.9.1/psych/nodes/node.rb:36:in `to_yaml'
    c:/Ruby192/lib/ruby/1.9.1/psych.rb:166:in `dump'
    c:/Ruby192/lib/ruby/1.9.1/psych/core_ext.rb:13:in `psych_to_yaml'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:706:in `node_export'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:706:in `add'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:706:in `encode_with'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:728:in `block (2 levels) in to_yaml'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:727:in `map'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:727:in `block in to_yaml'
    c:/Ruby192/lib/ruby/1.9.1/syck.rb:401:in `call'
    c:/Ruby192/lib/ruby/1.9.1/syck.rb:401:in `emit'
    c:/Ruby192/lib/ruby/1.9.1/syck.rb:401:in `quick_emit'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:726:in `to_yaml'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:78:in `block (2 levels) in write_package'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:73:in `block (3 levels) in add_gem_contents'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_writer.rb:83:in `new'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:67:in `block (2 levels) in add_gem_contents'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:65:in `wrap'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:65:in `block in add_gem_contents'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_writer.rb:113:in `add_file'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:63:in `add_gem_contents'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package/tar_output.rb:31:in `open'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/package.rb:68:in `open'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:77:in `block in write_package'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:76:in `open'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:76:in `write_package'
    c:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/builder.rb:39:in `build'
    c:/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler/commands/build_gem.rb:16:in `run'
    c:/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler.rb:87:in `build_gem'
    c:/Ruby192/lib/ruby/gems/1.9.1/gems/jeweler-1.5.2/lib/jeweler/tasks.rb:84:in `block in define'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:634:in `call'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:634:in `block in execute'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:629:in `each'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:629:in `execute'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain'
    c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:605:in `block in invoke_prerequisites'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:602:in `each'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:602:in `invoke_prerequisites'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:594:in `block in invoke_with_call_chain'
    c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:581:in `invoke'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `each'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
    c:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in `run'
    c:/Ruby192/bin/rake:31:in `<main>'
  7. I also got the DevKit from http://rubyinstaller.org/downloads, following these directions to set up: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit (I used this to "gem install rcov --platform=ruby", but it was not necessary since the next step covers it.)
  8. bundle install which results to installing a bunch of gems and saying "Your bundle is complete!"
  9. rake install
    Successfully built RubyGem
    ...
    ...
    ERROR: Error installing ./pkg/ethernet-0.0.0.gem:
                   ERROR: Failed to build gem native extension.

                   c:/Ruby192/bin/ruby.exe extconf.rb
    checking for a bunch of stuff ...
    This is because I haven't written the Windows parts of the gem yet! :D
  10. Continued in this blog
  11. to-do 4/4: read about MSDN

II. Linux: Find how to list all the network card names
I need to look into the system calls behind ifconfig to see how it lists all the network card device names.

  • http://linux.die.net/man/2/syscalls has system calls
  • I tried strace ifconfig 2> ifctrace.txt
  • Google for "sourcecode ifconfig", found a bsd version to-do 1/4: read it to figure out how linux list devices!

Sunday, March 27, 2011

Can't push on Github

When I tried to git push new commits into github, it asks:

Enter password to unlock the private key
An application wants access to the private key
'[my email]' but it is locked.

I tried all my passwords but it didn't work. Google didn't help much either.

Victor is here to help:

It means you password-protected your SSH keys, despite all the advice
against doing so.

The easiest fix is to blow up and re-generate your keys.

cd ~/.ssh
rm id_*
ssh-keygen
# Do NOT enter a password; just press Enter every time it asks a question
cat id_rsa.pub
# Go to GitHub -> account settings -> ssh public keys -> add another public key

Now I can finally navigate to my project directory and do
git push

Saturday, March 26, 2011

making youtubelooper.com notes

http://youtubelooper.com/

htmlentities() - to prevent xss
urlencode() - to keep the lyric's spaces and new lines
<label> - to click on


<textarea onclick="this.focus(); this.select();"></textarea> - make it select all when clicked

style changes

Fixed something on bottom right of page with CSS:

     position: fixed;
     bottom: 0;  
     right: 0;

css to make pointer into a hand
    cursor: pointer;


get jquery: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
jQuery to focus on something at the beginning:

  $(document).ready(function(){
      $("#inputboxid").focus();
  });



name.com sigh doesn't allow very long URL's

Friday, March 25, 2011

checkboxes and labels should get married

Yes, they should. Why limit yourself to only clicking on the tiny checkboxes? It's not a game.
Please group the text of input checkboxes together with labels!



html:
<label><input name="option" value="1" type="checkbox">The text is so long so you can have lots of places to click</label>

Thursday, March 24, 2011

Read about Ruby Modules

RSpec
Read about Rspec Testing. Link 1. Link 2 gives a great introduction to RSpec, and good TDD example. let(). :colon_things

See how it's applied to Victor's ether_shell: git clone https://github.com/pwnall/ether_shell.git and navigate to its "spec" directory to run the rspec tests.

Install rspec: sudo gem install rspec.

Run an RSpec test to see it produces RSpec outputs! :)
ether_shell/spec/ether_shell$ rspec raw_socket_spec.rb
FFFFF

Failures:

1) RawSocket mac should have 6 bytes
Failure/Error: let(:mac) { EtherShell::RawSocket.mac eth_device }
Errno::EPERM:
Operation not permitted - socket(2)
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `initialize'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `new'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `socket'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:31:in `mac'
# ./raw_socket_spec.rb:5
# ./raw_socket_spec.rb:14

2) RawSocket mac should match ifconfig output
Failure/Error: let(:mac) { EtherShell::RawSocket.mac eth_device }
Errno::EPERM:
Operation not permitted - socket(2)
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `initialize'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `new'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `socket'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:31:in `mac'
# ./raw_socket_spec.rb:5
# ./raw_socket_spec.rb:18

3) RawSocket socket should be able to receive data
Failure/Error: before { @socket = EtherShell::RawSocket.socket eth_device }
Errno::EPERM:
Operation not permitted - socket(2)
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `initialize'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `new'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `socket'
# ./raw_socket_spec.rb:25

4) RawSocket socket should output a packet
Failure/Error: before { @socket = EtherShell::RawSocket.socket eth_device }
Errno::EPERM:
Operation not permitted - socket(2)
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `initialize'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `new'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `socket'
# ./raw_socket_spec.rb:25

5) RawSocket socket should receive some network noise
Failure/Error: before { @socket = EtherShell::RawSocket.socket eth_device }
Errno::EPERM:
Operation not permitted - socket(2)
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `initialize'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `new'
# /home/haoqili/Desktop/rails/secureSt/ether_shell/spec/../lib/ether_shell/raw_socket.rb:15:in `socket'
# ./raw_socket_spec.rb:25

Finished in 0.00203 seconds
5 examples, 5 failures

Tuesday, March 22, 2011

Testing out the old ethernet ping through Wireshark

Currently I have an empty ethernet gem. So after talking to Victor (thank you! quotes in here are Victor's words), I tested the old ethernet code before sticking it into my gem..

The big picture: Create some bytes from my mac address to flow through the ethernet card, and wireshark should capture this flow.

Today I tested out what Victor already wrote, for a minimum ethernet pinging. Later I should take his code and improve on it.

Outline of Testing Victor's Ethernet Pinging Code
  1. Install the scratchpad rubygem with rake install.
  2. Try the ether_ping command
  3. See if the ping is caught on Wireshark
More details on 2:
bin/ether_ping calls the ethernet code. When you install the gem, you get the files in its bin/ on your path. So the bin/ file
- sets things up
- reads command-line args
- and calls up the ethernet code

More details on 3:
Wireshark is used to debug, and you can click on the packets to see the data. All you need is the basic functionality of capturing.
I asked a question: Shouldn't the data be coming/going from the server or the P chip?
Victor answened: Layers. The ethernet layer doesn't care about who sends data to whom. The ethernet layer takes an ethernet card, a mac address, a bunch of bytes and puts the bytes on the wire.

Details of Testing Victor's Ethernet Pinging Code (highlighted commands are the final steps, skipping over me talking about errors)

  1. git pull in my local copy of Victor's scratchpad rubygem to update it. (Your latest entry from git log should match the newest update on scratchpad's github version)
  2. rake install

    (in /home/haoqili/Desktop/rails/secureSt/scratchpad)
    Successfully built RubyGem
    Name: scratchpad
    Version: 0.0.1
    File: scratchpad-0.0.1.gem
    Executing "ruby -S gem install ./pkg/scratchpad-0.0.1.gem":
    ruby -S gem install ./pkg/scratchpad-0.0.1.gem
    Fetching: eventmachine-0.12.10.gem (100%)
    Building native extensions. This could take a while...
    Fetching: ffi-1.0.7.gem (100%)
    Building native extensions. This could take a while...
    Fetching: json-1.5.1.gem (100%)
    Building native extensions. This could take a while...
    Successfully installed eventmachine-0.12.10
    Successfully installed ffi-1.0.7
    Successfully installed json-1.5.1
    Successfully installed scratchpad-0.0.1
    4 gems installed
    Installing ri documentation for eventmachine-0.12.10...
    Installing ri documentation for ffi-1.0.7...
    Installing ri documentation for json-1.5.1...
    Installing ri documentation for scratchpad-0.0.1...
    Installing RDoc documentation for eventmachine-0.12.10...
    Installing RDoc documentation for ffi-1.0.7...
    Installing RDoc documentation for json-1.5.1...
    Installing RDoc documentation for scratchpad-0.0.1...
    I was puzzled why it says 4 gems installed even though scratchpad only has 1 .gemspec. Victor told me that "it probably needed to install dependencies since this is the first time you installed it".
  3. Type ether_ping, and the output tells you how to use it:
    Usage: /home/haoqili/.rvm/gems/ruby-1.9.2-p136/bin/ether_ping net_interface ether_type dest_mac data
    net_interface: name of the Ethernet interface, e.g. eth0
    ether_type: packet type for the Ethernet II frame, in hex (2 bytes)
    dest_mac: destination MAC for the ping packets, in hex (6 bytes)
    data: ping packet data, in hex (0-padded to 64 bytes)
  4. Victor gave me ether_ping eth0 88B7 001122334455 aa00112233, which was his test command for ether_ping. The ether_type Ethernet II frame is "88B7", which is "in the range of experimental protocols, but you can pretty much use anything that's not IP and you won't confuse your system." He also told me all the other exeprimental etherent II frames "are 4 numbers somewhere around the one I picked.". So I tried ether_ping eth0 88B7 001122334455 aa00112233, which gave:
    /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `initialize': Operation not permitted - socket(2) (Errno::EPERM)
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `new'
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `socket'
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/ping.rb:59:in `initialize'
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/bin/ether_ping:21:in `new'
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/gems/scratchpad-0.0.1/bin/ether_ping:21:in `<top (required)="">'
    from /home/haoqili/.rvm/gems/ruby-1.9.2-p136/bin/ether_ping:19:in `load'
    </top>

    Puzzled at the output, Victor told me to "sudo", because an "EMPERM is an OS-level error", not something that's wrong with the command I put. I then attepted sudo ether_ping eth0 88B7 001122334455 aa00112233, but it failed as well.
    [sudo] password for haoqili:
    sudo: ether_ping: command not found
    • bin/enable_pcacp: Victor said btw that "in the scratchpad gem there's a script [bin/enable_pcacp] that gives Ruby the right access bits so you don't have to sudo all the time to talk to the ethernet."
    • After I did sudo enable_pcap, I got: [sudo] password for haoqili: sudo: enable_pcap: command not found.
    • Victor: it's issuing setcap. So try setcap and see what it tells you to install: sudo setcap, output-ing sudo setcap usage: blahbalh Note <filename> must be a regular (non-symlink) file.
    What could be wrong with ether_ping that neither sudo-ing it or not works? Continue reading ...
  5. I tried which ether_ping, yielding /home/haoqili/.rvm/gems/ruby-1.9.2-p136/bin/ether_ping, instead of /usr/bin/ether_ping! CULPRINT FOUND! Fixing this should fix ether_ping! But it took me a while to fix it.
  6. ether_ping is pointed to the wrong location because I was using rvm (Victor is so smart), "so it installed scratchpad in one of your gemsets. You need to install it in the system rubygems, rvm use system, then rake install" To which I suggested of simply stop using rvm, but Victor said "rvm is useful, you'll need to make sure your thing works in 1.8.7 and 1.9.2. So it's good to use it in general. It doesn't do well with sudo though."
  7. But I got confused on what to do exactly, so Victor told me for now to just "remove the rvm import from your bash profile and use the system ruby for now like you suggested" rvm --default use system note the dash is actually 2 dashes. It worked:
    find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

    Now using system ruby.
    find: warning: you have specified the -maxdepth option after a non-option argument -name, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.

    Now using system ruby.
  8. Now I have to rake install, but first I encountered a program when doing rake install:
    (in /home/haoqili/Desktop/rails/secureSt/scratchpad)
    Jeweler (or a dependency) not available. Install it with: gem install jeweler
    rake aborted!
    Don't know how to build task 'install'

    (See full trace by running task with --trace)
  9. As suggested, I did: sudo gem install jeweler, outputting:
    Fetching: git-1.2.5.gem (100%)
    Fetching: jeweler-1.5.2.gem (100%)
    Successfully installed git-1.2.5
    Successfully installed jeweler-1.5.2
    2 gems installed
    Installing ri documentation for git-1.2.5...
    Installing ri documentation for jeweler-1.5.2...
    Installing RDoc documentation for git-1.2.5...
    Installing RDoc documentation for jeweler-1.5.2...
  10. rake install for reals this time!
    (in /home/haoqili/Desktop/rails/secureSt/scratchpad)
    Successfully built RubyGem
    Name: scratchpad
    Version: 0.0.1
    File: scratchpad-0.0.1.gem
    Executing "ruby1.8 -S gem install ./pkg/scratchpad-0.0.1.gem":
    ruby1.8 -S gem install ./pkg/scratchpad-0.0.1.gem
    Fetching: eventmachine-0.12.10.gem (100%)
    Building native extensions. This could take a while...
    Fetching: ffi-1.0.7.gem (100%)
    Building native extensions. This could take a while...
    Fetching: json-1.5.1.gem (100%)
    Building native extensions. This could take a while...
    Successfully installed eventmachine-0.12.10
    Successfully installed ffi-1.0.7
    Successfully installed json-1.5.1
    Successfully installed scratchpad-0.0.1
    4 gems installed
    Installing ri documentation for eventmachine-0.12.10...
    Installing ri documentation for ffi-1.0.7...
    Installing ri documentation for json-1.5.1...
    Installing ri documentation for scratchpad-0.0.1...
    Installing RDoc documentation for eventmachine-0.12.10...
    Could not find main page README
    Could not find main page README
    Could not find main page README
    Could not find main page README
    Installing RDoc documentation for ffi-1.0.7...
    Installing RDoc documentation for json-1.5.1...
    Installing RDoc documentation for scratchpad-0.0.1...
  11. ether_ping eth0 88B7 001122334455 aa00112233 still gives this error like before
    /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `initialize': Operation not permitted - socket(2) (Errno::EPERM)
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `new'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/raw_ethernet.rb:11:in `socket'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/ping.rb:59:in `initialize'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/bin/ether_ping:21:in `new'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/bin/ether_ping:21
    from /usr/bin/ether_ping:19:in `load'
    from /usr/bin/ether_ping:19
  12. So instead do sudo ether_ping eth0 88B7 001122334455 aa00112233
    Pinging 001122334455...
    looking great so far!

    I stop it with CTRL+C because "it's a ping tool so it expects a response back. There won't be a response because there isn't anyone listening at that MAC [001122334455] so it'll hang forever."
    Pinging 001122334455... ^C/usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/ping.rb:82:in `recv': Interrupt
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/lib/scratchpad/ethernet/ping.rb:82:in `ping'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/bin/ether_ping:26
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/bin/ether_ping:23:in `loop'
    from /usr/lib/ruby/gems/1.8/gems/scratchpad-0.0.1/bin/ether_ping:23
    from /usr/bin/ether_ping:19:in `load'
    from /usr/bin/ether_ping:19
  13. I open up Wireshark with sudo wireshark and start capturing "eth0". I run the above sudo ether_ping command again hoping something would show up, but it didn't. Again, I ask Victor to help because he knows everything about this project and is always patient with me asking questions. Victor says: "it may reject the packet because it's not formatted for wifi. Point ether_ping to a lan card, eth* [eth0 works]." But I did point it to eth0. "Maybe it doesn't work without a cable in it. I don't think I ever tested without a cable."
  14. Plug in a Ethernet cable into your computer! Don't do wireless!
  15. This command should work (finally!):
    sudo ether_ping eth0 88B7 001122334455 aa00112233

    In Wireshark, you should see:


    Click on it and click on "data" look! "aa00112233" is right there!!! Good job!!


Friday, March 11, 2011

self todo

  • egl: change ether_ping to what I will have
  • 6.858 combine with my course notes
  • add css to older posts

Pre tag
<pre class="prettyprint" style="font-size: small;">


TESTS


class co. Code test abcdef class hqhighlight ghijklmn opqrstuvwxyz
ABCDEF GHIJKLMN
OPQRSTUVWXY



class outs. Outs test class hqhighlight abcdef ghijklmn opqrstuvwxyz
ABCDEF GHIJKLMN
OPQRSTUVWXY



class outs. CLASS HQSMALL. Outs test abcdef ghijklmn opqrstuvwxyz
ABCDEF class hqhighlight GHIJKLMN
OPQRSTUVWXY



class errors. class hqhighlight Errors test abcdef ghijklmn opqrstuvwxyz
ABCDEF GHIJKLMN
OPQRSTUVWXY


class flip
class panel

Thursday, March 10, 2011

Setting up Github and RubyGems Profile for My Stuff

Set up Github

I found that the git configuration is expecting me to make a "ethrernet" project: "./.git/config: url = git@github.com:haoqili/ethernet.git"

So I'm going to set up my github account, which I got a few weeks ago. I followed these github bootcamp instructions to get my SSH keys.

Yay! It's done! https://github.com/haoqili/ethernet

Committing to Github from computer
  1. make edits
  2. git status
  3. git add [the modified files]
  4. git commit -m "message here"
  5. git push will push to github!
Setup RubyGems Profile btw, gemcutter.org redirects to rubygems.org
  1. sudo gem update --system
  2. bundle install ~ this adds Gemfile.lock
  3. vim VERSION ~ if you don't already have a "VERSION" file
  4. git add VERSION ~ put in "0.0.0" in it
  5. git commit -m "added a VRESION"
  6. git push
  7. rake release
If you get this error message for rake release (see below), this is because you don't have a VERSION file with "0.0.0" in it:

(in /home/haoqili/Desktop/rails/ethernet)
Committing ethernet.gemspec
Pushing master to origin
Tagging v
Pushing v to origin
Generated: ethernet.gemspec
ethernet.gemspec is valid.
  Successfully built RubyGem
  Name: ethernet
  Version: 
  File: ethernet-.gem
Executing "gem push ./pkg/ethernet-.gem":
gem push ./pkg/ethernet-.gem
Pushing gem to https://rubygems.org...
There was a problem saving your gem: Number is invalid
rake aborted!
Command failed with status (1): [gem push ./pkg/ethernet-.gem...]

(See full trace by running task with --trace)

Search for project name on rubygems.org. I have http://rubygems.org/gems/ethernet

IP Addresses are Endpoints of Net Links, NOT Number Names of Machines!

Today's 6.033 routing lecture was awesome!

There are forwarding tables and routing tables. Routing tables map destination to all possible paths. Then forwarding tables can be constructed by picking the best path to each destination.
$ route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.16.197.0    *               255.255.255.0   U     0      0        0 vmnet8
172.16.76.0     *               255.255.255.0   U     0      0        0 vmnet1
128.31.32.0     *               255.255.252.0   U     2      0        0 wlan0
link-local      *               255.255.0.0     U     1000   0        0 wlan0
default         guest-wireless. 0.0.0.0         UG    0      0        0 wlan0


I also learned about AS's -- Autonomous Systems for BGP routing. Every ISP has an AS. Multiple IP address prefixes can be mapped to an AS. For example, MIT's AS is 3, and 18.0.0.0/8 and 128.30.0.0/15 map to it (the 0's mean it could be anything).

Then we learned about Tier 1 and Tier 2 networks. There are only 10ish tier 1 networks and they make a complete graph. The tier 2 networks have to pay tier 1 for transit links (tier 2 using a tier 1 as a router). There are free peering links that tier 2 networks can set up among themselves for free.  There are also customer links connected to tier 2 for people buying that tier 2's service.

Every router may have many IP addresses, because it has different links/edges, and each IP address represent that router's end of the link/edge.  So an IP address does not represent a machine, but represent endpoints of net links.

Ping and Traceroute for internet

From the 6.033 assignment on "Internet Routes and Measuring Round Trip Times," I learned to use ping, which sends ICMP (similar to IP) request packets, for example: ping -c 10 -s 56 www.csail.mit.edu


But ping doesn't work for www.microsoft.com and some other sites, because they block ICMP due to security reasons. But most sites don't block ICMP because, ICMP is way, way more than "traceroute" and "ping." It is used for feedback when you run a DNS server (port unreachable) which, in a modern DNS server, may actually help select a different machine to query faster. (source)

Then we used traceroute, which prints the route packets trace to network host. According to its man page, It utilizes the IP protocol's time to live (TTL) field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to the host.

Wednesday, March 9, 2011

Get Jeweler

This is the first report of my EGL Project (Ethernet Gem Library). To document what I do so that in case things go wrong I can go back and check.

A few days ago I read about RubyGems (p229–234, 247–250 of the Programming Ruby 1.9 The Pragmatic Programmers) book. I typed in the first few commands.

Then Victor told me to use Jeweler, which is "a library for managing and releasing RubyGem projects" and "a scaffold generator for starting new RubyGem projects".

After git clone, I followed the readme instructions to install: gem install jewler. Actually blindly following the readme instructions was not good, because it creates a "hello-gem" with its default test setup. I want a directory named "ethernet" and "rspec" for testing, so I did: jeweler --rspec ethernet

I chose the name "ethernet" for my gem library after confirming on the RubyGems.org site through a search that the name has not been taken.

Saturday, March 5, 2011

How to Pass a Python Array as an Argument

Copy the array like this before you pass into the method: arrayName[:], if you don't want your array to be changed inside the method/function.

Example. Compare line 9 with line 16:

Result:
no copy:
before: [1, 1, 1, 1]
in change(): [2, 1, 1, 1]
after: [2, 1, 1, 1]

with copy:
before: [1, 1, 1, 1]
in change(): [2, 1, 1, 1]
after: [1, 1, 1, 1]