How can I retrieve the IP address from a Windows in real time using python or PowerShell to continuously and dynamically authenticate that a user is accessing a specific resource via that IP address (it will be compared to a range of ip addresses specified by me)? I want this information for a product I’m developing. The following is a code i tried but it work statically i want to retrieve ip dynamically.
#Import pandas library import pandas as pd # Registered IP addresses RegIPs = ["192.168.1.1", "192.168.1.2", "192.168.10.4", "192.158.1.38","192.168.10.6", "192.168.0.10", "192.168.0.11", "192.168.2.30", "192.168.2.31", "192.168.1.21", "192.168.1.20"] def load_employee_info(): try: employees_info = pd.read_csv('Employees_info.csv') except FileNotFoundError: # If the file is not found, print an error message and return an empty data frame print("Error: Employees_info.csv file not found.") return pd.DataFrame() return employees_info # Filter the dataframe to get the row with the specified user_id def retrieve_ip_address_risk_score(user_id, rip): employees_info = load_employee_info() if employees_info.empty: # If the data frame is empty, return a risk level of 1 (High Risk) print("Error: Employees_info.csv file is empty.") return 1 users = employees_info.loc[employees_info["user_id"] == user_id] if users.empty: # If the user ID is not found, print an error message and return a risk level of 1 (High Risk) print("Error: User ID not found.") return 1 # Extract the IP address from the filtered row try: incomingIP = users["ip_address"].values[0] except IndexError: # If the IP address cannot be extracted, print an error message and return a risk level of 1 (High Risk) print("Error: Unable to retrieve IP address.") return 1 if incomingIP != rip: Risk_level = 1 else: Risk_level = 0.1 # Return the Risk level return Risk_level
I tried nmap with python code but didn’t work.
SurgeFier is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1