Class: PacketGen::Header::IP

Inherits:
Object
  • Object
show all
Defined in:
lib/capra/packetgen_extensions.rb

Instance Method Summary collapse

Instance Method Details

#external_communication?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/capra/packetgen_extensions.rb', line 78

def external_communication?
  !internal_communication_only?
end

#external_destination?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/capra/packetgen_extensions.rb', line 86

def external_destination?
  !internal_destination?
end

#external_source?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/capra/packetgen_extensions.rb', line 94

def external_source?
  !internal_source? 
end

#from_subnet?(cidr) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/capra/packetgen_extensions.rb', line 103

def from_subnet?(cidr)
  subnet = IPAddr.new(cidr)
  subnet.include?(self.src)
end

#from_subnets?(cidrs) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/capra/packetgen_extensions.rb', line 108

def from_subnets?(cidrs)
  cidrs.map { IPAddr.new(cidr) }.include?(self.src)
end

#internal_communication_only?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/capra/packetgen_extensions.rb', line 74

def internal_communication_only?
  PRIVATE_IPS.any? { |private_ip| private_ip.include?(self.src) } and PRIVATE_IPS.any? { |private_ip| private_ip.include?(self.dst) }
end

#internal_destination?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/capra/packetgen_extensions.rb', line 82

def internal_destination?
  PRIVATE_IPS.any? { |private_ip| private_ip.include?(self.dst) }
end

#internal_source?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/capra/packetgen_extensions.rb', line 90

def internal_source?
  PRIVATE_IPS.any? { |private_ip| private_ip.include?(self.src) }
end

#to_subnet?(cidr) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
115
# File 'lib/capra/packetgen_extensions.rb', line 112

def to_subnet?(cidr)
  subnet = IPAddr.new(cidr)
  subnet.include?(self.dst)
end

#to_subnets?(cidr) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/capra/packetgen_extensions.rb', line 117

def to_subnets?(cidr)
  cidrs.map { IPAddr.new(cidr) }.include?(self.dst)
end

#within_subnet?(cidr) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
# File 'lib/capra/packetgen_extensions.rb', line 98

def within_subnet?(cidr)
  subnet = IPAddr.new(cidr)
  subnet.include?(self.src) or subnet.include?(self.dst)
end