#!/usr/bin/perl use strict; use Tk; use IO::Socket::INET; my $poll_result = ""; my $sel_node; my $service = init_service(); my $mw = new MainWindow(title => "Service Polling"); my $operation_frame = $mw->Frame(relief => "sunken", background => "pink", borderwidth => 1) ->pack(fill => "x"); my $entry = $operation_frame->Entry(width => 20, textvariable => \$sel_node) ->pack(side => "left", padx => 5); $entry->bind("", \&poll_service); $operation_frame->Button(text => "Connect", background => "green", activebackground => "yellow", command => \&poll_service) ->pack(side => "left", padx => 5, pady => 5); my $node_list = $mw->Scrolled("Listbox", background => "pink", height => 10, yscrollcommand => \&change_service, -scrollbars => "e") ->pack(fill => "x"); $node_list->bind("", \&change_service); $node_list->bind("", \&change_service); $node_list->bind("", \&change_service); $node_list->bind("", \&poll_service); foreach (keys %{$service}) { $node_list->insert("end", $_); } $mw->Label(textvariable => \$poll_result, foreground => "red", anchor => "w") ->pack(fill => "x"); MainLoop; sub init_service { my $services = {}; while () { m/^(.*?)\s+(.*)$/; $service->{$2} = $1; } return $service; } sub change_service { $node_list->focus(); my $sel_index = $node_list->curselection; $sel_node = $service->{$node_list->get($sel_index)} if (defined($sel_index)); } sub poll_service { if (defined($sel_node)) { $sel_node =~ /(.*?):(.*)/; my $connection = new IO::Socket::INET(Proto => "tcp", PeerAddr => $1, PeerPort => $2); $poll_result = (defined($connection)) ? "Service available" : " Service unavailable"; close($connection) if (defined($connection)); } } __DATA__ ofgaix2:27011 AADV1 WebLogic ofgaix2:28001 AAUA1 WebLogic ofgaix2:27021 AATS1 WebLogic