Pages

Tuesday, August 5, 2014

SNMP Notes

SNMP:
======
Simple network management protocol
-runs over UDP ports 161/162

Management Information Base (MIB)
-used to read/write a variable in the device configuration

Network management station(NMS) asks managed device(can be router or switch) the status of a MIB
-called  SNMP polling

Managed devices(ie agents) may also report unsolicited events
-called SNMP Traps or Informs(informs are acknowledged but traps are not, traps are unreliable)

MIB is platform and version specific. Snmpwalk is used by NMS to poll every variable in MIB to verify what version and platform it supports. Once all the MIBS are known, u can poll for whatever u want.

SNMP versions
===========
Three main versions
-V1: supports only community authentication
-V2c: support community authentication and views(ie what management station can view which MIB)
-V3: supports users/groups, encryption, and secure authentication. (can assign views to different users and apply users to groups) then we can apply permission to see/change the specific value of MIB on the router.

SNMP V1/V2c Polling
====================
Configured as snmp-server community
[string ] [ro | rw] [acl]
Community string
-clear-text password for NMS to poll device
Two types of community stringd
-read only
-read/write (configuration changes remotely or reloading router remotely)
ACL defines who can poll device

SNMP Traps
=============
Device  reports unsolicited events to NMS
Reports could be
-unreliable: traps (configure in cases when CPU threshold exceeded, network interface goes down)
-reliable: informs. Informs are acknowledged.
-Both are sent using UDP to port 162.

SNMP v1/v2c Traps
=============
Define events to trap
-All traps
Snmp-server enable traps
-Specific Traps
Snmp-server enable traps [notification-type]

Now define to which all NMS these traps are sent to
Define host to send traps to
-All enabled traps
. snmp-server host host-addr community-string

-Subset of enabled traps
. snmp-server host host-addr community-string [notification-type]

Note: all these commands are executed in agents (router or switches).

SNMPv3
===========
Three main entities
-Users
. Define operators accessing the routers
-Groups
. Group users, access privileges assigned to groups
-         - Views
. Define subsets of MIB visible to groups (like only allowed to see system MIB, or interface MIB or CPU MIB)

SNMP v3 Security
============
Access to MIB is either
-          Unauthenitcated/Unencrypted
. NoauthNo Priv
-          Authenticated only
. AuthNoPriv
-          Authenticated and encrypted
. AuthPriv

SNMP v3 Traps
=============
Supports Traps/Informs
Authentication model is different
Trap needs to have a user associated
User’s credentials are used to authenticate
The NMS needs to implement authentication

SNMP v3 configuration
==================
View
-          Snmp-server view MYVIEW cisco included
Group
-          Snmp-server group MYGROUP v3 priv read MYVIEW
User
-          Snmp-server user MYUSER MYGROUP v3 auth md5 PASSWORD priv des ENCRYPTKEY
Trap

-          Snmp-server host 10.0.0.100 trap version 3 auth MYUSER cpu syslog

RMON:
====
Remote Monitoring
-used to monitor MIB variables
Monitoring has two components
-Alarm
. Condition to trigger event
-Event
. Action to associate to alarm
. Normally a syslog message/SNMP Trap

RMON Alarm
===============
RMON alarm defines how MIB is sampled


Alternate of SNMP
An alternative to SNMP (Simple Network Management Protocol) is the NETCONF (Network Configuration Protocol) protocol. NETCONF is a standardized network management protocol developed by the IETF (Internet Engineering Task Force) to provide a more modern and flexible approach to network device management compared to SNMP. Here are some key differences and features of NETCONF compared to SNMP:

1. **Data Model**: SNMP uses a hierarchical management information base (MIB) to represent and organize managed objects. NETCONF, on the other hand, uses YANG (Yet Another Next Generation) data modeling language to define the structure and semantics of configuration and operational data exchanged between network devices and management systems. YANG provides a more structured and expressive way to describe data models compared to MIBs.

2. **Configuration and Operations**: NETCONF supports both configuration management and operational data retrieval operations. It allows network administrators to remotely configure and manage network devices using standardized RPC (Remote Procedure Call) operations defined in the NETCONF protocol. This includes operations such as get, set, edit-config, delete-config, and more.

3. **Transport Protocol**: SNMP typically uses UDP (User Datagram Protocol) as its transport protocol, which can be less reliable and secure compared to TCP (Transmission Control Protocol). NETCONF, on the other hand, uses SSH (Secure Shell) as its transport protocol by default, providing secure and encrypted communication between network devices and management systems.

4. **Transaction Support**: NETCONF provides transactional support for configuration changes, allowing administrators to group multiple configuration changes into a single atomic transaction. This ensures consistency and reliability when applying configuration changes to network devices.

5. **Extensibility**: NETCONF is designed to be extensible and supports the use of custom data models and extensions. This allows vendors to define vendor-specific data models and capabilities while still interoperating with standard NETCONF implementations.

Overall, NETCONF offers a more modern and flexible approach to network management compared to SNMP, with support for structured data modeling, transactional configuration changes, and secure transport. It is increasingly being adopted by network vendors and operators as a replacement or complement to SNMP for managing and configuring network devices.




Monday, February 10, 2014

regexp

Regular expressions (regex) are a powerful tool for pattern matching and text manipulation in Python. Some of the most commonly used regex patterns in Python include:

1. **Matching a Literal String**:
   - `pattern = 'hello'`: Matches the literal string 'hello'.

2. **Matching Any Character**:
   - `pattern = '.'`: Matches any single character except newline.

3. **Matching Digits**:
   - `pattern = '\d'`: Matches any digit (equivalent to `[0-9]`).
   - `pattern = '\D'`: Matches any non-digit character.

4. **Matching Word Characters**:
   - `pattern = '\w'`: Matches any alphanumeric character (equivalent to `[a-zA-Z0-9_]`).
   - `pattern = '\W'`: Matches any non-word character.

5. **Matching Whitespace Characters**:
   - `pattern = '\s'`: Matches any whitespace character (space, tab, newline).
   - `pattern = '\S'`: Matches any non-whitespace character.

6. **Anchors**:
   - `pattern = '^start'`: Matches 'start' only at the start of the string.
   - `pattern = 'end$'`: Matches 'end' only at the end of the string.

7. **Quantifiers**:
   - `pattern = 'a+'`: Matches one or more occurrences of 'a'.
   - `pattern = 'a*`': Matches zero or more occurrences of 'a'.
   - `pattern = 'a?'`: Matches zero or one occurrence of 'a'.
   - `pattern = 'a{2,4}'`: Matches 2 to 4 occurrences of 'a'.

8. **Character Classes**:
   - `pattern = '[aeiou]'`: Matches any vowel character.
   - `pattern = '[A-Z]'`: Matches any uppercase letter.
   - `pattern = '[0-9]'`: Matches any digit.

9. **Grouping and Capturing**:
   - `pattern = '(abc)+'`: Matches one or more occurrences of 'abc'.
   - `pattern = '(\d+)-(\w+)'`: Matches a digit followed by a hyphen and then any word characters.

10. **Alternation**:
    - `pattern = 'cat|dog'`: Matches either 'cat' or 'dog'.

These are just a few examples of commonly used regex patterns in Python. Regular expressions offer a wide range of functionality for more advanced text processing tasks, such as searching, replacing, and extracting information from strings.


Postal Address 
[a-zA-Z\d\s\-\,\#\.\+]+

set address "
   Mr S Tan
   #200, Broadway Av
   WEST BEACH SA 5024  
   AUSTRALIA"

regexp {[a-zA-Z\d\s\-\,\#]+} $address new
puts $new


ZIP Code  
^\d{5,6}(?:[-\s]\d{4})?$


Date – accept date input in the mm/dd/yyyy or mm-dd-yyyy formats.
((0[1-9])|(1[0-2]))[\/-]((0[1-9])|(1[0-9])|(2[0-9])|(3[0-1]))[\/-](\d{4})

set date "31/01/1000"
regexp {(0[1-9]|1[0-9]|2[0-9]|3[0-1])/(0[1-9]|1[0-2])/(\d{4})} $date match
puts $match


Email Address  
[a-zA-Z0-9_\.\+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-\.]+

set email "Naw_raj.lekhak01@spirent.com"
regexp {[a-zA-Z0-9_]+.[0-9a-zA-Z_]+@[a-z0-9A-Z_]+.[a-zA-Z_]+} $email match
puts $match


URL (Web domain)
https?\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}
https?\:\/\/(www\.)?youtu(\.)?be(\.com)?\/.*(\?v=|\/v\/)?[a-zA-Z0-9_\-]+

set site "https://www.facebook.com/"
regexp {(http|https)://www.[a-z]+.[a-z]+} $site match
puts $match

Character Limit 
[\w]{1,140}

Phone Numbers  
\+?\(?\d{2,4}\)?[\d\s-]{3,}

Price (with decimal)  
\$?\d{1,3}(,?\d{3})*(\.\d{1,2})?

Complex Password – only accept a string that has 1 uppercase alphabet, 1 lowercase alphabet, 2 digits and 1 special character. Also the minimum allowed length is 8 characters.
(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9].*[0-9])(?=.*[^a-zA-Z0-9]).{8,}



Thursday, January 16, 2014

TCL procs

Ip address increment :
proc generate_ips {start_ip number_of_ips} {
    regexp {([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)} $start_ip - oct1 oct2 oct3 oct4
    set ip_list ""
    while {[llength $ip_list] < $number_of_ips} {
        for {} {$oct4 <= 254} {incr oct4} {
            lappend ip_list "$oct1.$oct2.$oct3.$oct4"
            if {[llength $ip_list] == $number_of_ips} {
                break
            }
        }
        if {$oct4 == 255} {
            set oct4 0
            incr oct3
        }
        if {$oct3 == 256} {
            set oct3 0
            incr oct2
        }
        if {$oct2 == 256} {
            set oct2 0
            incr oct1
        }
        if {$oct1 == 256} {
            break
        }
    }
    return $ip_list
}
set start_ip "103.0.0.2"
set ip_list [generate_ips $start_ip 5]
puts $ip_list
puts [llength $ip_list]

In python:
Here's a Python program that prints 1000 IPv4 addresses in incremental fashion:

```python
def print_ipv4_addresses(start_ip="192.168.0.1", count=1000):
    # Split the start IP address into octets
    parts = start_ip.split('.')
    octets = [int(part) for part in parts]

    # Loop through the count of IPv4 addresses
    for _ in range(count):
        # Print the current IP address
        print('.'.join(map(str, octets)))

        # Increment the last octet
        octets[3] += 1

        # Adjust other octets if necessary
        for i in range(3, 0, -1):
            if octets[i] > 255:
                octets[i] = 0
                octets[i - 1] += 1
            else:
                break

# Call the function to print IPv4 addresses
print_ipv4_addresses()
```

This program defines a function `print_ipv4_addresses` that takes two optional parameters: `start_ip` (the starting IPv4 address, default is "192.168.0.1") and `count` (the number of IPv4 addresses to print, default is 1000).

The function splits the starting IP address into octets and increments them in a loop while printing the resulting IPv4 addresses. If an octet exceeds 255, it rolls over to 0 and the next octet is incremented accordingly. This process continues until the desired number of IPv4 addresses are printed.


mac address increment :

proc generate_mac {start_mac number_of_mac} {
    regexp {([0-9a-fA-F]+)([0-9a-fA-F]+)\:([0-9a-fA-F]+)([0-9a-fA-F]+)\:([0-9a-fA-F]+)([0-9a-fA-F]+)\:([0-9a-fA-F]+)([0-9a-fA-F]+)\:([0-9a-fA-F]+)([0-9a-fA-F]+)\:([0-9a-fA-F]+)([0-9a-fA-F]+)} $start_mac - hex1 hex2 hex3 hex4 hex5 hex6 hex7 hex8 hex9 hex10 hex11 hex12
    set mac_list ""
    array set hex_list {0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F 16 16}
    array set hex_list {0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 a 11 b 12 c 13 d 14 e 15 f 16 16}
    array set dec_list {0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B 11 C 12 D 13 E 14 F 15} 
    array set dec_list {0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 a 10 b 11 c 12 d 13 e 14 f 15}
    set hex12 $dec_list($hex12)
    while {[llength $mac_list] < $number_of_mac} {
        for {} {$hex12 <= 15} {incr hex12} {
            set hex12_new $hex_list($hex12)
            lappend mac_list "$hex1$hex2:$hex3$hex4:$hex5$hex6:$hex7$hex8:$hex9$hex10:$hex11$hex12_new"
            if {[llength $mac_list] == $number_of_mac} {
                break
            }
        }
        if {$hex12 == 16} {
            set hex12 0
            set hex11 $dec_list($hex11)
            incr hex11
            set hex11 $hex_list($hex11)
        }
        if {$hex11 == 16} {
            set hex11 0
            set hex10 $dec_list($hex10)
            incr hex10
            set hex10 $hex_list($hex10)
        }
        if {$hex10 == 16} {
            set hex10 0
            set hex9 $dec_list($hex9)
            incr hex9
            set hex9 $hex_list($hex9)
        }
        if {$hex9 == 16} {
            set hex9 0
            set hex8 $dec_list($hex8)
            incr hex8
            set hex8 $hex_list($hex8)
        }
        if {$hex8 == 16} {
            set hex8 0
            set hex7 $dec_list($hex7)
            incr hex7
            set hex7 $hex_list($hex7)
        }
        if {$hex7 == 16} {
            set hex7 0
            set hex6 $dec_list($hex6)
            incr hex6
            set hex6 $hex_list($hex6)
        }
        if {$hex6 == 16} {
            set hex6 0
            set hex5 $dec_list($hex5)
            incr hex5
            set hex5 $hex_list($hex5)
        }
        if {$hex5 == 16} {
            set hex5 0
            set hex4 $dec_list($hex4)
            incr hex4
            set hex4 $hex_list($hex4)
        }
        if {$hex4 == 16} {
            set hex4 0
            set hex3 $dec_list($hex3)
            incr hex3
            set hex3 $hex_list($hex3)
        }
        if {$hex3 == 16} {
            set hex3 0
            set hex2 $dec_list($hex2)
            incr hex2
            set hex2 $hex_list($hex2)
        }
        if {$hex2 == 16} {
            set hex2 0
            set hex1 $dec_list($hex1)
            incr hex1
            set hex1 $hex_list($hex1)
        }
        if {$hex1 == 16} {
            break
        }
    }
    return $mac_list
}
set start_mac "10:ef:09:14:a0:7e"
set mac_list [generate_mac $start_mac 100]
puts $mac_list
puts [llength $mac_list]


In Python:

Here's a Python program that increments a MAC address:

```python
def increment_mac_address(mac_address):
    # Split MAC address into octets
    octets = mac_address.split(':')

    # Convert each octet to an integer
    for i in range(len(octets)):
        octets[i] = int(octets[i], 16)

    # Increment the last octet
    octets[-1] += 1

    # Handle carry-over if necessary
    for i in range(len(octets) - 1, 0, -1):
        if octets[i] > 255:
            octets[i] = octets[i] % 256
            octets[i - 1] += 1
        else:
            break

    # Convert octets back to hexadecimal string format
    incremented_mac = ':'.join([format(octet, '02x') for octet in octets])

    return incremented_mac

# Example usage
original_mac = '00:11:22:33:44:ff'
incremented_mac = increment_mac_address(original_mac)
print("Original MAC address:", original_mac)
print("Incremented MAC address:", incremented_mac)
```

This program defines a function `increment_mac_address` that takes a MAC address as input and returns the incremented MAC address. The function splits the MAC address into octets, increments the last octet, and handles carry-over if necessary. Finally, it converts the octets back to hexadecimal string format and returns the incremented MAC address.

You can call this function with a MAC address as input to increment it.


Python program that generates and prints 1000 sequential IPv4 addresses, starting from 192.168.0.1

import ipaddress

def generate_ipv4_addresses(start_ip, count):
    # Convert starting IP to an ipaddress object
    ip = ipaddress.IPv4Address(start_ip)
    
    # Generate addresses
    for i in range(count):
        print(str(ip + i))

# Generate 1000 addresses starting from 192.168.0.1
generate_ipv4_addresses("192.168.0.1", 1000)