Archive for June, 2007

Listen on port – client server demo

Problem You want to listen on a port, maybe to test firewalls! Excellent introduction to client server software. Solution Another use bit of socket programming, courtesy of Perl! Extremely useful bit of Perl, which can be used with the other post on this site, to confirm network connectivity (port scanner).This code (see example tab) will [...]

LDAP LDIF Perl search script

Problem You want to search an LDIF file for a given dn, or pattern. Solution Multi-line pattern search and output – useful for LDIFs! Written in Perl – see example tab. Example Replace pattern to a given name, etc and filename to LDIF output file.perl -ane '$/="dn" ;print,"\n\n" if($_ =~/pattern/);' filenameFor example:$ cat user.ldifdn: cn=user0,dc=subdiv,dc=demo,dc=netobjectClass: [...]

Modify LDAP records with JNDI

Problem Need to modify an LDAP record with JNDI, the Java Naming Directory Interface.Following on from using java to perform LDAP searches, here is a quick demo on modifying records. Solution Here I’m using java to modify John Doe’s record, changing the givenname entry to John A.As you’ll notice all values are hard coded (such [...]

scan network port with perl

Problem You want to test a network port, on a remote system – over TCP/IP.Maybe this is a new setup, or you want confirmation it is working.Perhaps the firewall rules have just been changed! Solution A nice small bit of Perl code that I’ve used thousands of times!In fact I’m running it in most of [...]

Obtain epoch time and calculate date yesterday

Problem You want to capture the current epoch. Maybe to use in a log file, or as a filename.Or maybe you want to calculate the date yesterday. Solution This piece of code is very useful for performing date calculations. You can obtain the current epoch (time in seconds since Jan 1 1970), then add 3600 [...]

Calculate largest field big data file

Problem I wanted to upload a delimited field to mysql db, but hit the problem that the file contained nearly 3000 rows and no schema on the required size of each field.Therefore I needed to traverse the file and calculate the length of each field. Then at the end, print the largest field found for [...]

ldapsearch logical NOT

Problem You want to perform an LDAP search, matching entries which do not match certain criteria. Solution To perform a logical NOT we just use the exclamation mark ! – see example. Example This is how to perform a logical OR LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(!(sn=Doe))" Reference Technorati Tags: ldapsearch syntax, openldap ldapsearch, [...]

ldapsearch logical AND

Problem You want to match more than one field, in your LDAP search. Solution To match more than one field we use the ampersand – “&” with ldapsearch. Example This is how to perform a logical AND LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(&(givenname=John)(sn=Smith))" Reference Technorati Tags: ldapsearch syntax, openldap ldapsearch, LDAP Training SchoolLDAP Docs [...]

ldapsearch with logical OR

Problem You want to match more one or another pattern, in your LDAP search. Solution To match more one pattern or another we use the pipe symbol “|” . Example This is how to perform a logical OR LDAP search.ldapsearch -x -v-D"cn=Manager,dc=demo,dc=net"-w secret \-b"dc=demo,dc=net" "(|(sn=Doe)(sn=Smith))" Reference Technorati Tags: ldapsearch syntax, openldap ldapsearch, LDAP Training SchoolLDAP [...]

Deleting LDAP Record

Problem You want to delete a LDAP entry. Solution In this example, we just use ldapdelete from the command line.Remember to take a backup. ldapsearch with -L Example Here is an example of deleting a record in LDAP:ldapdelete -v -D’cn=Manager..’ -w ${passwd} \ -h ${host} -p ${port}<<EOTcn=….EOTEffectively – you just need to supply the full [...]