Remove logging to file
This commit is contained in:
parent
fb9d358eee
commit
8abe0d6293
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
||||
*.log
|
@ -1,10 +1,9 @@
|
||||
require_relative "netlib.rb"
|
||||
require "packetfu"
|
||||
cable=EtherCable.new("etherlog.log")
|
||||
cable=EtherCable.new(true)
|
||||
dev1=EtherSocket.new(cable,"d2:f5:8a:c4:22:56")
|
||||
dev2=EtherSocket.new(cable,"d2:f5:8a:22:65:4c")
|
||||
ArpUtils.add_arp_resp(dev2,"192.168.0.56")
|
||||
ipsock=MyIPSocket.new(dev1,"192.168.0.34")
|
||||
ipsock1=MyIPSocket.new(dev1,"192.168.0.34")
|
||||
ipsock2=MyIPSocket.new(dev2,"192.168.0.56")
|
||||
ipsock.send_packet("hello","192.168.0.56")
|
||||
ipsock.send_packet("hi","192.168.0.56")
|
||||
ipsock1.send_packet("hello","192.168.0.56")
|
||||
ipsock1.send_packet("hi","192.168.0.56")
|
||||
|
11
netlib.rb
11
netlib.rb
@ -1,4 +1,3 @@
|
||||
require "logger"
|
||||
require "packetfu"
|
||||
class EtherSocket
|
||||
attr_reader :mac
|
||||
@ -26,20 +25,14 @@ class EtherSocket
|
||||
end
|
||||
|
||||
class EtherCable
|
||||
def initialize(lfile=nil)
|
||||
def initialize(log=false)
|
||||
@socks=[]
|
||||
if lfile
|
||||
@log=true
|
||||
@logger=Logger.new(File.open(lfile,"w"))
|
||||
else
|
||||
@log=false
|
||||
end
|
||||
@log=log
|
||||
end
|
||||
def add_device(socket)
|
||||
@socks.push(socket)
|
||||
end
|
||||
def send_packet(packet,sock)
|
||||
@logger.info "Frame of type #{packet[2]} from #{packet[0]} to #{packet[1]} with data #{packet[3]}" if @log
|
||||
puts "Frame of type #{packet[2]} from #{packet[0]} to #{packet[1]} with data #{packet[3]}" if @log
|
||||
@socks.each { |socket| next if sock==socket; socket.got_packet(packet) }
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user