From 71fc4bd2192e7116ba72d4f7c313893ac4357584 Mon Sep 17 00:00:00 2001 From: bmc <> Date: Fri, 21 Apr 2006 03:59:07 +0000 Subject: [PATCH] * random states * random hostnames git-svn-id: file:///home/svn/incoming/trunk@3605 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/text.rb | 21 +++++++++++++++++++++ lib/rex/text.rb.ut.rb | 2 ++ 2 files changed, 23 insertions(+) diff --git a/lib/rex/text.rb b/lib/rex/text.rb index 5f117efdef..8927519804 100644 --- a/lib/rex/text.rb +++ b/lib/rex/text.rb @@ -23,6 +23,11 @@ module Text # ## + States = ["AK", "AL", "AR", "AZ", "CA", "CO", "CT", "DE", "FL", "GA", "HI", + "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", + "MO", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", + "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", + "WI", "WV", "WY"] UpperAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" LowerAlpha = "abcdefghijklmnopqrstuvwxyz" Numerals = "0123456789" @@ -608,6 +613,22 @@ module Text return arr end + # Generate a random hostname + def self.rand_hostname + host = [] + (rand(5) + 1).times { + host.push(Rex::Text.rand_text_alphanumeric(rand(10) + 1)) + } + d = ['com', 'net', 'org', 'gov'] + host.push(d[rand(d.size)]) + host.join('.').downcase + end + + # Generate a state + def self.rand_state() + States[rand(States.size)] + end + protected def self.converge_sets(sets, idx, offsets, length) # :nodoc: diff --git a/lib/rex/text.rb.ut.rb b/lib/rex/text.rb.ut.rb index 1d0ef75e05..b8a594a0dd 100644 --- a/lib/rex/text.rb.ut.rb +++ b/lib/rex/text.rb.ut.rb @@ -27,6 +27,8 @@ class Rex::Text::UnitTest < Test::Unit::TestCase assert_equal("\025\362$WF\330X\214:\301", Rex::Text.rand_text(10), 'rand text 2') assert_equal("\346'W\256XQ\245\031MH", Rex::Text.rand_text(10), 'rand text 3') assert_equal('bababbabba', Rex::Text.rand_text(10, nil, 'ab'), 'rand text with specified "good"') + assert_equal('MA', Rex::Text.rand_state(), 'rand state') + assert_equal('xzdttongb.5gfk0xjly3.aak.fmo0rp.com', Rex::Text.rand_hostname(), 'rand hostname') end