Skip to main content

Posts

Showing posts with the label script

Simple Python function to validate IP address

 Here is a simple Python function that checks if a given string is a valid IP address: import re  def is_valid_ip ( ip ):       pattern = re. compile ( r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" )       return pattern. match (ip) is not None This function uses a regular expression to check if the input string is a valid IP address. The regular expression is compiled and stored in the variable 'pattern'. The match function is used to check if the string passed to the function matches the regular expression. If it does, the function returns True, otherwise, it returns False. You can test the function by calling it and passing a string as an argument: print (is_valid_ip( "192.168.0.1" )) # True   print (is_valid_ip( "256.256.256.256" )) # False Note that this function will only check if the string passed to it is a valid IP address in the format of 'xxx.xxx.xxx.xxx' where x...

Creating Multiple Home Directories with Custom Permissions

In this post we will see a way to create multiple home directories, remove inherited permissions, remove other users, and then give the user write access to the folder. 1. Create Share for Home Directories On your file server, create a share that will hold all your home directories. Be sure to allow Domain Users to have read access to this share 2. Get a list of all users We wanted the home directories to have the same name as the user's login name. I was able to export a list from Active Directory of all the login names. Save this as a text file with the name file.txt 3. Batch file to create directories Make a batch file with the following lines to create the home directories: @echo off for /f %%i in (file.txt) do mkdir %%i Place this batch file in the root of the share along with the file.txt. Run the batch to create the folders. 4. Removing Inheritance We don't want user's to be able to see the contents of other user's home directories. First we...