extract ip address from string powershell pattern
$Results = @()
$Hosts = @()
$Server = "Server01"
$LogPath = "C:\logs\$Server\logs\server.log"
#Checking log file
$Lines = Get-Content $LogPath | Where-Object {$_ -match "AUDIT "}
#Remotely
#$Lines = icm -cn $Server {param($LogPath)Get-Content $LogPath | Where-Object {$_ -match "AUDIT "}} -ArgumentList $LogPath
#Getting IP Addresses
Foreach ($Line in $Lines) {
$IP = $Object1 = $null
$IP = ($Line | Select-String -Pattern "\d{1,3}(\.\d{1,3}){3}" -AllMatches).Matches.Value
IF($IP -notmatch "0.0.0.0"){
$Object1 = New-Object PSObject -Property @{
IPAddress = $IP
}
$Results += $Object1
}
}
#Selecting unique IPs
$IPUnique = $Results | Select-Object IPAddress -Unique
#Checking hostname
Foreach ($Item in $IPUnique) {
$HostName = $Object2 = $null
$HostName = (Resolve-DnsName $Item.IPAddress -ErrorAction SilentlyContinue).NAMEHOST
If(!$HostName){$Hostname = "None"}
$Object2 = New-Object PSObject -Property @{
IPAddress = $item.ipaddress
NameHost = $HostName
}
$Hosts += $Object2
}
$Hosts | Out-GridView -Title "Hostnames"
Also in C++:
- I want to give a specific color to git
- unzip tar.xz linux
- batch rename folder
- windows echo environment variable
- sed remove last 3 lines
- install fzf redhat 8
- edit path linux
- adobe acrobat reader for linux download
- extract gz file ubuntu
- ssh welcome message ubuntu
- show version laravel
- ubuntu install pip
- ubuntu root login ssh
- installing isomorphic-fetch and simply doing
- Failed to run "javac -version", make sure that you have a JDK version 8 installed. You can get it from the following location: https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- how to get mcp23017 input in binary shell
- shell mac move faster
- npx eslint fix
- ubuntu yarn gpg error signature invalid
- ubuntu install zsh
- bash delete first n characters of each line
- terraform state
- git error needs merge
- terminal git add ssh key