Thread Liste in Tabellenformat umwandeln (19 answers)
Opened by Rambo at 2016-06-24 15:19

Rambo
 2016-07-18 15:33
#185102 #185102
User since
2003-08-14
803 Artikel
BenutzerIn

user image
Dank eurer Hilfe tut das script jetzt das was es soll. Vielen Dank für eure Hilfe und falls jemand mal so was sucht gibt es hier meine Code Zeilen:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
#!/usr/bin/perl -w
################################################################################
#
# AUTHOR : xyz
# CREATION DATE : 18 July 2016
#
# SHORT DESCRIPTION:
# find all AD/LDAP user and login credentials
# (c) RH 2016
#
# -----------------------------------------------------------------------------
# File name : search_ldap_user_v1_20160718.pl
# Location : ESB
# Last edited by : RH
# Last Checkin :
# Revision : 0.1
# -----------------------------------------------------------------------------
# History:
#
# 18.07.2016 first version
#
# -----------------------------------------------------------------------------
#
# Last change: 18.07.2016 RH
#
################################################################################
#
#
# ------------------------------------------------------------------
# Loaded Modules
# ------------------------------------------------------------------
use strict;
use warnings;
use Net::LDAP;

# ------------------------------------------------------------------
# ldap parameters
# ------------------------------------------------------------------
my $ldap_srv = 'server1.domain.com';
my $ldap_usr = 'CN=Username,OU=User,OU=ESB,OU=DE,DC=domain,DC=com';
my $ldap_pwd = 'geheim';
my $ldap_base_dir = 'dc=domain,dc=com';

# ------------------------------------------------------------------
# connect to ldap
# ------------------------------------------------------------------
my $ldap = Net::LDAP->new( $ldap_srv ) or die "$@";
my $mesg = $ldap->bind( $ldap_usr,
password => $ldap_pwd
);

# ------------------------------------------------------------------
# search LDAP database
# ------------------------------------------------------------------
$mesg = $ldap->search( base=>$ldap_base_dir,
filter => "(&(objectclass=user)(sn=*))");
#filter=>"(name=*)",

my @entries = $mesg->entries;
foreach my $entry (@entries) {
my $samACC = $entry->get_value('samAccountName');
my $name = $entry->get_value('name');
my $descr = $entry->get_value('description');
my $lastLogon = readable_wintime($entry->get_value('lastLogon'));
my $pwdLastSet = readable_wintime($entry->get_value('pwdLastSet'));
my $mail = $entry->get_value('mail');
print "UserID:$samACC\t
User Name:$name\t
Beschreibung:$descr\t
Letzter Login:$lastLogon\t
Last_PWD_Set:$pwdLastSet\t
Email:$mail\n";
}

# ------------------------------------------------------------------
# disconnect from ldap
# ------------------------------------------------------------------
$mesg = $ldap->unbind; # take down session

# ------------------------------------------------------------------
# convert none readable date/time format to readable format
# ------------------------------------------------------------------
sub readable_wintime {
my $wintime = shift;
my $unix_epoch = win_to_unix_epoch($wintime);
my ($year, $month, $day, $hour, $minute, $second) = (localtime $unix_epoch)[5,4,3,2,1,0];
$year += 1900;
$month += 1;
($month, $day, $hour, $minute, $second) = map { sprintf '%02d', $_ } $month, $day, $hour, $minute, $second;
my $LastLogin = join('-', $day, $month, $year) . ' ' . join(':', $hour, $minute, $second);
}
sub win_to_unix_epoch {
# Actually hundreths of nanoseconds at this point...
my $nanoseconds = shift;
# Get seconds
my $seconds = $nanoseconds / 10_000_000;
# This magic number is the difference between Unix and Windows epoch.
my $unix_epoch = $seconds - 11644473600;
# Return the Unix epoch for use with localtime().
return $unix_epoch;
}

View full thread Liste in Tabellenformat umwandeln