<domainname>\<username> smb/116 Jun 12 09:32 (10.0.10.9)
Here's the script:
#!/usr/bin/perl -w # Script to deliver the IP address or get name based on the samba # connections list in 'who' (choice depending on parameter match) use strict; my @whocontents = `who`; my ($line, %user, %ipaddress, $username, $ip); # Process contents of the 'who' command; foreach (@whocontents) { if (m/\\([a-z0-9]+)/) { $username = $1; m/(\d+\.\d+\.\d+\.\d+)/; $ip = $1; $user{$username} = $1; $ipaddress{$1} = $username; } } # Set up formatting for the 'runall' subroutine format something = @<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<< $_, $user{$_} . # Perl format case statement for ($ARGV[0]) { if (/^\d+\.\d+\.\d+\.\d+/) {&runip;} # Prints usern +ame elsif (/^all$/) {&runall;} # Prints all u + & ip elsif (/^[a-z]+/) {&runname;} # Prints out I +P elsif (!$ARGV[0]) {&runusage;} # Prints usage } sub runusage { print "GETIPUSER: Prints the IP address of a supplied username +\n"; print "or a username associated with a supplied IP address.\n" +; print "(OR enter 'all' to get a list of all users and ips)\n"; print "\n"; print "Examples:\n"; print " ./getipuser 10.0.29.33\n"; print " ./getipuser gwebster\n"; print " ./getipuser all\n"; print "(requires that usernames not start with a number)\n"; } sub runname { if ($user{$ARGV[0]}) { print "$user{$ARGV[0]}\n"; } else { print "User is not connected to a samba share on this +machine.\$ } }; sub runip { if ($ipaddress{$ARGV[0]}) { print "$ipaddress{$ARGV[0]}\n"; } else { print "User is not connected to a samba share on this +machine.\$ } }; sub runall { $~ = 'something'; foreach (sort (keys(%user))) { write; } }
Kickstart
edited - 17 June 2002 (footpad): Added <READMORE> Tag.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Updated simple code
by Kickstart (Pilgrim) on Jun 26, 2002 at 20:38 UTC |