Releases: suchsoak/IP_List_Ruby
IP LIST
▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄
█ █ █ █ █ █ █ █ █
█ █ ▄ █ █ █ █ █ ▄▄▄▄▄█▄ ▄█
█ █ █▄█ █ █ █ █ █ █▄▄▄▄▄ █ █
█ █ ▄▄▄█ █ █▄▄▄█ █▄▄▄▄▄ █ █ █
█ █ █ █ █ █▄▄▄▄▄█ █ █ █
█▄▄▄█▄▄▄█ █▄▄▄▄▄▄▄█▄▄▄█▄▄▄▄▄▄▄█ █▄▄▄█
∼∼https://github.com/suchsoak/IP_List_Ruby∼∼
suchsoak
~~v:1.0.4~~
What change
To be honest not much, I just fixed and modified the script to be more favorable and not to occur too many errors. I made it more robust compared to how it was before.
I put automated clear to clean up the terminal and get a better look at the script:
if clear
system("cls")
else
system("clear")
end
I also put a warning to press enter, to make it more intuitive:
if gets.chomp == ""
puts "Search...".rjust(27)
else
puts ""
end
I've also put in an error handler:
rescue Errno::Interrupt
puts "\nScript Interrupt".colorize(:red)
retry
exit
rescue IPAddr::InvalidAddressError
puts "\n Invalid Addres"
end
I also put the json
file:
{ "version": [
{ "version": "1.0.4",
"ruby": "ruby 3.0.2p107 (2021-07-07 revision 0db68f0233)",
"name": "IP LIST",
"file": "list_ip.rb",
"libary": "socket, ipaddr, colorize and time",
"github": "www.github.com/suchsoak",
"Author": "suchsoak"
}
]
}
IP_List_Ruby
▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄ ▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄
█ █ █ █ █ █ █ █ █
█ █ ▄ █ █ █ █ █ ▄▄▄▄▄█▄ ▄█
█ █ █▄█ █ █ █ █ █ █▄▄▄▄▄ █ █
█ █ ▄▄▄█ █ █▄▄▄█ █▄▄▄▄▄ █ █ █
█ █ █ █ █ █▄▄▄▄▄█ █ █ █
█▄▄▄█▄▄▄█ █▄▄▄▄▄▄▄█▄▄▄█▄▄▄▄▄▄▄█ █▄▄▄█
∼∼https://github.com/suchsoak/IP_List_Ruby∼∼
suchsoak
~~v:1.0.3~~
Details
This Ruby script performs a scanner of IP ports on a user-specified range of IPs. It has two main functions: scan_ips and get_service_name. The scan_ips function accepts three arguments: start_ip: The starting IP of the range. end_ip: The final IP of the range. port_list: A list of ports to check on each IP. The script uses the range syntax (IPAddr.new(start_ip).. IPAddr.new(end_ip)) to iterate over each IP in the specified range.
Within the scan_ips function, the script performs a nested iteration on each IP and each port in the list. It attempts to establish a TCP connection to each IP and port combination using the TCPSocket.new(ips.to_s, port) constructor. If the connection is successful, the script uses the get_service_name function to get the name of the service associated with that port. It also prints the IP and port combination in a green colored line.
If the connection fails, the script throws an exception. If the exception is of a specific type, it simply proceeds with the next IP and port combination. If the exception is of an unhandled type (such as Interrupt), the script throws the exception again, stopping the script from executing. The get_service_name function accepts a single argument: port. It uses the getent services #{port} system call to get the name of the service associated with that port. The service name is returned after removing the leading and trailing spaces using the strip method and splitting the line into words using the split(' ' method)
Code
def scan_ips(start_ip, end_ip, port_list)
(IPAddr.new(start_ip)..IPAddr.new(end_ip)).each do |ips|
port_list.each do |port|
begin
socket = TCPSocket.new(ips.to_s, port)
service = get_service_name(port)
prot = socket.peeraddr[0]
puts "\t\t\t\t\t", "|#{ips}| \t |#{port}" "\t #{service}|" "\t |#{prot}|".colorize(:green)
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, IO::TimeoutError, IPAddr::InvalidAddressError
rescue Interrupt
puts "\nScript Interrupt".colorize(:red)
exit
end
end
end
end
def get_service_name(port)
`getent services #{port}`.strip.split(' ')[0]
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, IO::TimeoutError, IPAddr::InvalidAddressError
rescue Interrupt
puts "\nScript Interrupt".colorize(:red)
exit
end