Skip to content

Instantly share code, notes, and snippets.

@shutingrz
Last active March 22, 2016 16:24
Show Gist options
  • Save shutingrz/f71d863d379347aa91b0 to your computer and use it in GitHub Desktop.
Save shutingrz/f71d863d379347aa91b0 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
#@shutingrz
require File.expand_path(File.dirname(__FILE__) + '/vitocha.rb')
# jails path
$jails='/jails'
#Operator is shutingrz!!
shu=Operator.new
#create Jail.
if File.exist?('/jails/root') == false then
system('/bin/sh mkserver root')
end
if File.exist?('/jails/jp') == false then
system('/bin/sh mkserver jp')
end
if File.exist?('/jails/example') == false then
system('/bin/sh mkserver example')
end
if File.exist?('/jails/cache') == false then
system('/bin/sh mkserver cache')
end
if File.exist?('/jails/pedcache') == false then
system('/bin/sh mkserver pedcache')
end
if File.exist?('/jails/Switch5') == false then
system('/bin/sh mkrouter Switch5')
end
if File.exist?('/jails/attacker') == false then
system('/bin/sh mkserver attacker')
end
if File.exist?('/jails/Server7') == false then
system('/bin/sh mkserver Server7')
end
#start Jail.
shu.setupserver('root')
shu.setupserver('jp')
shu.setupserver('example')
shu.setupserver('cache')
shu.setupserver('pedcache')
shu.setupbridge('Switch5')
shu.setupserver('attacker')
shu.setupserver('Server7')
#create link.
epaira, epairb=shu.createpair
shu.connect('root', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('jp', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('example', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('cache', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('attacker', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('Server7', epaira)
shu.connect('Switch5', epairb)
epaira, epairb=shu.createpair
shu.connect('pedcache', epaira)
shu.connect('Switch5', epairb)
#set IPAddr.
shu.assignip('root','epair0a','192.168.11.11','255.255.255.0')
shu.up('root','epair0a')
shu.up('Switch5','epair0b')
shu.assignip('jp','epair1a','192.168.11.12','255.255.255.0')
shu.up('jp','epair1a')
shu.up('Switch5','epair1b')
shu.assignip('example','epair2a','192.168.11.13','255.255.255.0')
shu.up('example','epair2a')
shu.up('Switch5','epair2b')
shu.assignip('cache','epair3a','192.168.11.14','255.255.255.0')
shu.up('cache','epair3a')
shu.up('Switch5','epair3b')
shu.assignip('attacker','epair4a','192.168.11.15','255.255.255.0')
shu.up('attacker','epair4a')
shu.up('Switch5','epair4b')
shu.assignip('Server7','epair5a','192.168.11.16','255.255.255.0')
shu.up('Server7','epair5a')
shu.up('Switch5','epair5b')
shu.assignip('pedcache','epair6a','192.168.11.17','255.255.255.0')
shu.up('pedcache','epair6a')
shu.up('Switch5','epair6b')
#set Gateway.
# for DUMMYNET
system("sysctl net.link.bridge.ipfw=1")
epaira, epairb=shu.createpair
system("ifconfig #{epairb} vnet Switch5")
system("jexec Switch5 ifconfig #{epairb} up")
system("jexec Switch5 ifconfig vbridge0 addm #{epairb}")
system("ifconfig #{epaira} up")
system("ifconfig #{epaira} 192.168.11.1/24")
puts "Finish!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment