Class: CSRtelnet_1

Inherits:
Object
  • Object
show all
Defined in:
lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iwag1_host, iwag_username, iwag_password) ⇒ CSRtelnet_1

Returns a new instance of CSRtelnet_1.



9
10
11
12
13
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 9

def initialize(iwag1_host, iwag_username, iwag_password)
  @iwag1_host = iwag1_host
  @iwag_username = iwag_username
  @iwag_password = iwag_password
end

Instance Attribute Details

#iwag1_hostObject

Returns the value of attribute iwag1_host.



7
8
9
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 7

def iwag1_host
  @iwag1_host
end

#iwag_passwordObject

Returns the value of attribute iwag_password.



7
8
9
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 7

def iwag_password
  @iwag_password
end

#iwag_usernameObject

Returns the value of attribute iwag_username.



7
8
9
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 7

def iwag_username
  @iwag_username
end

Instance Method Details

#get_iwag_info_ssh_1(ipaddress) ⇒ Object

test function. Not used



53
54
55
56
57
58
59
60
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 53

def get_iwag_info_ssh_1(ipaddress)
  p DateTime.now
  Net::SSH.start(iwag1_host, iwag_username, :password => iwag_password) do |ssh|
    result = ssh.exec!("show ip dhcp binding #{ipaddress}\n")
    p result
  end
  p DateTime.now
end

#get_subs_mac2_1(ipaddress) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 15

def get_subs_mac2_1(ipaddress)

  subscribers_mac = ""

  #begin

    dump =""
    connection = Net::Telnet.new( "Host" => iwag1_host, "Timeout" => false, "Prompt" => /.*/ ) { |str| }
    connection.({ "Name" => iwag_username, "Password" => iwag_password, "LoginPrompt" => /Username:/ }) { |str|  }
    connection.cmd("show ip dhcp binding #{ipaddress}") {
        |c|
      p c
      dump << c
    }
    connection.close
    as = dump.split("\n")
    p as
    reer = as[4].split(" ")

    ma = reer[1].to_s.upcase
    pos = ma[0]+ma[1]
    if pos == '01'
      subscribers_mac = ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]+":"+ma[15]+ma[16]
    else
      subscribers_mac = ma[0]+ma[1]+":"+ma[2]+ma[3]+":"+ma[5]+ma[6]+":"+ma[7]+ma[8]+":"+ma[10]+ma[11]+":"+ma[12]+ma[13]
    end


  #rescue
  #  subscribers_mac = "unknown"
  #end

  subscribers_mac

end

#return_iwag_access_interface_1(ipaddress) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/imperituroard/platforms/iwag/iwag_telnet_connector.rb', line 64

def return_iwag_access_interface_1(ipaddress)
  host_iwag = iwag1_host
  username_iwag = iwag_username
  password_iwag = iwag_password
  answer =""

  dump =""
  begin
    connection = Net::Telnet.new("Host" => host_iwag, "Timeout" => false, "Prompt" => /.*/) {|str| print str}
    connection.({"Name" => username_iwag, "Password" => password_iwag, "LoginPrompt" => /Username:/}) {|str| print str}
    connection.cmd("show ip dhcp binding #{ipaddress}") {
        |c|
      dump << c
    }
    connection.close
    as = dump.split("\n")

    if as[4] != nil && as[3] != ""
      access_interface = as[4].gsub!("  ", "").split(" ").last
      return access_interface
    else
      answer = 'false'
      return answer
    end
  rescue
    begin
      connection = Net::Telnet.new('Host' => host_iwag, 'Timeout' => false, 'Prompt' => /.*/) {|str| print str}
      connection.({'Name' => username_iwag, 'Password' => password_iwag, 'LoginPrompt' => /Username:/}) {|str| print str}
      connection.cmd("show ip dhcp binding #{ipaddress}") {
          |c|
        dump << c
      }
      connection.close
      as = dump.split("\n")
      if as[4] != nil && as[3] != ""
        access_interface = as[4].gsub!("  ", "").split(" ").last
        return access_interface
      else
        answer ='false'
        return answer
      end
    rescue
      return 'unknown'
    end
  end
end