Spaces:
Sleeping
Sleeping
Commit ·
2d8b3a4
1
Parent(s): 40ea8bd
Disable FaceFinder module to bypass dlib compilation
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +0 -0
- favicon.ico +0 -0
- pages/{7_FaceFinderOSINT.py → 7_FaceFinderOSINT.py.disabled} +0 -0
- requirements.txt +0 -1
- spiderfoot/venv-spiderfoot/Scripts/Activate.ps1 +472 -0
- spiderfoot/venv-spiderfoot/Scripts/EXIF.py +129 -0
- spiderfoot/venv-spiderfoot/Scripts/activate +69 -0
- spiderfoot/venv-spiderfoot/Scripts/activate.bat +34 -0
- spiderfoot/venv-spiderfoot/Scripts/deactivate.bat +22 -0
- spiderfoot/venv-spiderfoot/Scripts/ipwhois_cli.py +1515 -0
- spiderfoot/venv-spiderfoot/Scripts/ipwhois_utils_cli.py +269 -0
- spiderfoot/venv-spiderfoot/Scripts/vba_extract.py +79 -0
- spiderfoot/venv-spiderfoot/pyvenv.cfg +5 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/LICENSE.txt +37 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/README.txt +2 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/mayavi2_spring.py +43 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/plot_basic.py +51 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/README.txt +8 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/README.txt +2 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/WormNet.v3.benchmark.txt +0 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/hartford_drug.edgelist +338 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_beam_search.py +112 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_betweenness_centrality.py +83 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_blockmodel.py +79 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_circuits.py +103 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_davis_club.py +43 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_dedensification.py +92 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_iterated_dynamical_systems.py +210 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_krackhardt_centrality.py +31 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_parallel_betweenness.py +82 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_rcm.py +40 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_snap.py +108 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/README.txt +2 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_properties.py +49 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_read_write.py +24 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_simple_graph.py +60 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/README.txt +2 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_chess_masters.py +152 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_custom_node_icons.py +75 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_degree.py +50 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_directed.py +46 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_edge_colormap.py +23 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_ego_graph.py +35 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_eigenvalues.py +22 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_four_grids.py +52 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_house_with_colors.py +26 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_knuth_miles.py +142 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_labels_and_colors.py +54 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_multipartite_graph.py +41 -0
- spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_node_colormap.py +15 -0
.gitignore
CHANGED
|
Binary files a/.gitignore and b/.gitignore differ
|
|
|
favicon.ico
DELETED
|
Binary file (15.4 kB)
|
|
|
pages/{7_FaceFinderOSINT.py → 7_FaceFinderOSINT.py.disabled}
RENAMED
|
File without changes
|
requirements.txt
CHANGED
|
@@ -11,6 +11,5 @@ TikTokApi
|
|
| 11 |
python-whois
|
| 12 |
plotly
|
| 13 |
exifread
|
| 14 |
-
face_recognition
|
| 15 |
duckduckgo_search
|
| 16 |
google-api-python-client
|
|
|
|
| 11 |
python-whois
|
| 12 |
plotly
|
| 13 |
exifread
|
|
|
|
| 14 |
duckduckgo_search
|
| 15 |
google-api-python-client
|
spiderfoot/venv-spiderfoot/Scripts/Activate.ps1
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<#
|
| 2 |
+
.Synopsis
|
| 3 |
+
Activate a Python virtual environment for the current PowerShell session.
|
| 4 |
+
|
| 5 |
+
.Description
|
| 6 |
+
Pushes the python executable for a virtual environment to the front of the
|
| 7 |
+
$Env:PATH environment variable and sets the prompt to signify that you are
|
| 8 |
+
in a Python virtual environment. Makes use of the command line switches as
|
| 9 |
+
well as the `pyvenv.cfg` file values present in the virtual environment.
|
| 10 |
+
|
| 11 |
+
.Parameter VenvDir
|
| 12 |
+
Path to the directory that contains the virtual environment to activate. The
|
| 13 |
+
default value for this is the parent of the directory that the Activate.ps1
|
| 14 |
+
script is located within.
|
| 15 |
+
|
| 16 |
+
.Parameter Prompt
|
| 17 |
+
The prompt prefix to display when this virtual environment is activated. By
|
| 18 |
+
default, this prompt is the name of the virtual environment folder (VenvDir)
|
| 19 |
+
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
| 20 |
+
|
| 21 |
+
.Example
|
| 22 |
+
Activate.ps1
|
| 23 |
+
Activates the Python virtual environment that contains the Activate.ps1 script.
|
| 24 |
+
|
| 25 |
+
.Example
|
| 26 |
+
Activate.ps1 -Verbose
|
| 27 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 28 |
+
and shows extra information about the activation as it executes.
|
| 29 |
+
|
| 30 |
+
.Example
|
| 31 |
+
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
| 32 |
+
Activates the Python virtual environment located in the specified location.
|
| 33 |
+
|
| 34 |
+
.Example
|
| 35 |
+
Activate.ps1 -Prompt "MyPython"
|
| 36 |
+
Activates the Python virtual environment that contains the Activate.ps1 script,
|
| 37 |
+
and prefixes the current prompt with the specified string (surrounded in
|
| 38 |
+
parentheses) while the virtual environment is active.
|
| 39 |
+
|
| 40 |
+
.Notes
|
| 41 |
+
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
| 42 |
+
execution policy for the user. You can do this by issuing the following PowerShell
|
| 43 |
+
command:
|
| 44 |
+
|
| 45 |
+
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
| 46 |
+
|
| 47 |
+
For more information on Execution Policies:
|
| 48 |
+
https://go.microsoft.com/fwlink/?LinkID=135170
|
| 49 |
+
|
| 50 |
+
#>
|
| 51 |
+
Param(
|
| 52 |
+
[Parameter(Mandatory = $false)]
|
| 53 |
+
[String]
|
| 54 |
+
$VenvDir,
|
| 55 |
+
[Parameter(Mandatory = $false)]
|
| 56 |
+
[String]
|
| 57 |
+
$Prompt
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
<# Function declarations --------------------------------------------------- #>
|
| 61 |
+
|
| 62 |
+
<#
|
| 63 |
+
.Synopsis
|
| 64 |
+
Remove all shell session elements added by the Activate script, including the
|
| 65 |
+
addition of the virtual environment's Python executable from the beginning of
|
| 66 |
+
the PATH variable.
|
| 67 |
+
|
| 68 |
+
.Parameter NonDestructive
|
| 69 |
+
If present, do not remove this function from the global namespace for the
|
| 70 |
+
session.
|
| 71 |
+
|
| 72 |
+
#>
|
| 73 |
+
function global:deactivate ([switch]$NonDestructive) {
|
| 74 |
+
# Revert to original values
|
| 75 |
+
|
| 76 |
+
# The prior prompt:
|
| 77 |
+
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
| 78 |
+
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
| 79 |
+
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# The prior PYTHONHOME:
|
| 83 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
| 84 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
| 85 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
# The prior PATH:
|
| 89 |
+
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
| 90 |
+
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
| 91 |
+
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# Just remove the VIRTUAL_ENV altogether:
|
| 95 |
+
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
| 96 |
+
Remove-Item -Path env:VIRTUAL_ENV
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
| 100 |
+
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
| 101 |
+
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
| 105 |
+
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
| 106 |
+
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
# Leave deactivate function in the global namespace if requested:
|
| 110 |
+
if (-not $NonDestructive) {
|
| 111 |
+
Remove-Item -Path function:deactivate
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
<#
|
| 116 |
+
.Description
|
| 117 |
+
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
| 118 |
+
given folder, and returns them in a map.
|
| 119 |
+
|
| 120 |
+
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
| 121 |
+
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
| 122 |
+
then it is considered a `key = value` line. The left hand string is the key,
|
| 123 |
+
the right hand is the value.
|
| 124 |
+
|
| 125 |
+
If the value starts with a `'` or a `"` then the first and last character is
|
| 126 |
+
stripped from the value before being captured.
|
| 127 |
+
|
| 128 |
+
.Parameter ConfigDir
|
| 129 |
+
Path to the directory that contains the `pyvenv.cfg` file.
|
| 130 |
+
#>
|
| 131 |
+
function Get-PyVenvConfig(
|
| 132 |
+
[String]
|
| 133 |
+
$ConfigDir
|
| 134 |
+
) {
|
| 135 |
+
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
| 136 |
+
|
| 137 |
+
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
| 138 |
+
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
| 139 |
+
|
| 140 |
+
# An empty map will be returned if no config file is found.
|
| 141 |
+
$pyvenvConfig = @{ }
|
| 142 |
+
|
| 143 |
+
if ($pyvenvConfigPath) {
|
| 144 |
+
|
| 145 |
+
Write-Verbose "File exists, parse `key = value` lines"
|
| 146 |
+
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
| 147 |
+
|
| 148 |
+
$pyvenvConfigContent | ForEach-Object {
|
| 149 |
+
$keyval = $PSItem -split "\s*=\s*", 2
|
| 150 |
+
if ($keyval[0] -and $keyval[1]) {
|
| 151 |
+
$val = $keyval[1]
|
| 152 |
+
|
| 153 |
+
# Remove extraneous quotations around a string value.
|
| 154 |
+
if ("'""".Contains($val.Substring(0, 1))) {
|
| 155 |
+
$val = $val.Substring(1, $val.Length - 2)
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
$pyvenvConfig[$keyval[0]] = $val
|
| 159 |
+
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
return $pyvenvConfig
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
<# Begin Activate script --------------------------------------------------- #>
|
| 168 |
+
|
| 169 |
+
# Determine the containing directory of this script
|
| 170 |
+
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
| 171 |
+
$VenvExecDir = Get-Item -Path $VenvExecPath
|
| 172 |
+
|
| 173 |
+
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
| 174 |
+
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
| 175 |
+
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
| 176 |
+
|
| 177 |
+
# Set values required in priority: CmdLine, ConfigFile, Default
|
| 178 |
+
# First, get the location of the virtual environment, it might not be
|
| 179 |
+
# VenvExecDir if specified on the command line.
|
| 180 |
+
if ($VenvDir) {
|
| 181 |
+
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
| 182 |
+
}
|
| 183 |
+
else {
|
| 184 |
+
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
| 185 |
+
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
| 186 |
+
Write-Verbose "VenvDir=$VenvDir"
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
# Next, read the `pyvenv.cfg` file to determine any required value such
|
| 190 |
+
# as `prompt`.
|
| 191 |
+
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
| 192 |
+
|
| 193 |
+
# Next, set the prompt from the command line, or the config file, or
|
| 194 |
+
# just use the name of the virtual environment folder.
|
| 195 |
+
if ($Prompt) {
|
| 196 |
+
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
| 197 |
+
}
|
| 198 |
+
else {
|
| 199 |
+
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
| 200 |
+
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
| 201 |
+
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
| 202 |
+
$Prompt = $pyvenvCfg['prompt'];
|
| 203 |
+
}
|
| 204 |
+
else {
|
| 205 |
+
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
| 206 |
+
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
| 207 |
+
$Prompt = Split-Path -Path $venvDir -Leaf
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
Write-Verbose "Prompt = '$Prompt'"
|
| 212 |
+
Write-Verbose "VenvDir='$VenvDir'"
|
| 213 |
+
|
| 214 |
+
# Deactivate any currently active virtual environment, but leave the
|
| 215 |
+
# deactivate function in place.
|
| 216 |
+
deactivate -nondestructive
|
| 217 |
+
|
| 218 |
+
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
| 219 |
+
# that there is an activated venv.
|
| 220 |
+
$env:VIRTUAL_ENV = $VenvDir
|
| 221 |
+
|
| 222 |
+
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
| 223 |
+
|
| 224 |
+
Write-Verbose "Setting prompt to '$Prompt'"
|
| 225 |
+
|
| 226 |
+
# Set the prompt to include the env name
|
| 227 |
+
# Make sure _OLD_VIRTUAL_PROMPT is global
|
| 228 |
+
function global:_OLD_VIRTUAL_PROMPT { "" }
|
| 229 |
+
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
| 230 |
+
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
| 231 |
+
|
| 232 |
+
function global:prompt {
|
| 233 |
+
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
| 234 |
+
_OLD_VIRTUAL_PROMPT
|
| 235 |
+
}
|
| 236 |
+
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
# Clear PYTHONHOME
|
| 240 |
+
if (Test-Path -Path Env:PYTHONHOME) {
|
| 241 |
+
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
| 242 |
+
Remove-Item -Path Env:PYTHONHOME
|
| 243 |
+
}
|
| 244 |
+
|
| 245 |
+
# Add the venv to the PATH
|
| 246 |
+
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
| 247 |
+
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
| 248 |
+
|
| 249 |
+
# SIG # Begin signature block
|
| 250 |
+
# MIIpigYJKoZIhvcNAQcCoIIpezCCKXcCAQExDzANBglghkgBZQMEAgEFADB5Bgor
|
| 251 |
+
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
|
| 252 |
+
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUAB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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!c:\Ba7ath_project\dashboard_osint\spiderfoot\venv-spiderfoot\Scripts\python.exe
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
#
|
| 4 |
+
#
|
| 5 |
+
# Library to extract Exif information from digital camera image files.
|
| 6 |
+
# https://github.com/ianare/exif-py
|
| 7 |
+
#
|
| 8 |
+
#
|
| 9 |
+
# Copyright (c) 2002-2007 Gene Cash
|
| 10 |
+
# Copyright (c) 2007-2020 Ianaré Sévi and contributors
|
| 11 |
+
#
|
| 12 |
+
# See LICENSE.txt file for licensing information
|
| 13 |
+
# See ChangeLog.rst file for all contributors and changes
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
"""
|
| 17 |
+
Runs Exif tag extraction in command line.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import sys
|
| 21 |
+
import argparse
|
| 22 |
+
import logging
|
| 23 |
+
import timeit
|
| 24 |
+
from exifread.tags import DEFAULT_STOP_TAG, FIELD_TYPES
|
| 25 |
+
from exifread import process_file, exif_log, __version__
|
| 26 |
+
|
| 27 |
+
logger = exif_log.get_logger()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_args():
|
| 31 |
+
parser = argparse.ArgumentParser(
|
| 32 |
+
prog='EXIF.py',
|
| 33 |
+
description='Extract EXIF information from digital image files.'
|
| 34 |
+
)
|
| 35 |
+
parser.add_argument(
|
| 36 |
+
'files', metavar='FILE', type=str, nargs='+',
|
| 37 |
+
help='files to process',
|
| 38 |
+
)
|
| 39 |
+
parser.add_argument(
|
| 40 |
+
'-v', '--version', action='version',
|
| 41 |
+
version='EXIF.py Version %s on Python%s' % (__version__, sys.version_info[0]),
|
| 42 |
+
help='Display version information and exit'
|
| 43 |
+
)
|
| 44 |
+
parser.add_argument(
|
| 45 |
+
'-q', '--quick', action='store_false', dest='detailed',
|
| 46 |
+
help='Do not process MakerNotes',
|
| 47 |
+
)
|
| 48 |
+
parser.add_argument(
|
| 49 |
+
'-t', '--tag', type=str, dest='stop_tag',
|
| 50 |
+
help='Stop processing when this tag is retrieved.',
|
| 51 |
+
)
|
| 52 |
+
parser.add_argument(
|
| 53 |
+
'-s', '--strict', action='store_true', dest='strict',
|
| 54 |
+
help='Run in strict mode (stop on errors).',
|
| 55 |
+
)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
'-d', '--debug', action='store_true', dest='debug',
|
| 58 |
+
help='Run in debug mode (display extra info).',
|
| 59 |
+
)
|
| 60 |
+
parser.add_argument(
|
| 61 |
+
'-c', '--color', action='store_true', dest='color',
|
| 62 |
+
help='Output in color (only works with debug on POSIX).',
|
| 63 |
+
)
|
| 64 |
+
args = parser.parse_args()
|
| 65 |
+
return args
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def main():
|
| 69 |
+
"""Parse command line options/arguments and execute."""
|
| 70 |
+
args = get_args()
|
| 71 |
+
|
| 72 |
+
exif_log.setup_logger(args.debug, args.color)
|
| 73 |
+
|
| 74 |
+
# output info for each file
|
| 75 |
+
for filename in args.files:
|
| 76 |
+
try:
|
| 77 |
+
escaped_fn = escaped_fn = filename.encode(
|
| 78 |
+
sys.getfilesystemencoding(), 'surrogateescape'
|
| 79 |
+
).decode()
|
| 80 |
+
except UnicodeDecodeError:
|
| 81 |
+
#TODO: Python2 specific, remove
|
| 82 |
+
escaped_fn = filename
|
| 83 |
+
|
| 84 |
+
file_start = timeit.default_timer()
|
| 85 |
+
try:
|
| 86 |
+
img_file = open(escaped_fn, 'rb')
|
| 87 |
+
except IOError:
|
| 88 |
+
logger.error("'%s' is unreadable", escaped_fn)
|
| 89 |
+
continue
|
| 90 |
+
logger.info('Opening: %s', escaped_fn)
|
| 91 |
+
|
| 92 |
+
tag_start = timeit.default_timer()
|
| 93 |
+
|
| 94 |
+
# get the tags
|
| 95 |
+
data = process_file(
|
| 96 |
+
img_file, stop_tag=args.stop_tag, details=args.detailed, strict=args.strict, debug=args.debug
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
tag_stop = timeit.default_timer()
|
| 100 |
+
|
| 101 |
+
if not data:
|
| 102 |
+
logger.warning("No EXIF information found\n")
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
if 'JPEGThumbnail' in data:
|
| 106 |
+
logger.info('File has JPEG thumbnail')
|
| 107 |
+
del data['JPEGThumbnail']
|
| 108 |
+
if 'TIFFThumbnail' in data:
|
| 109 |
+
logger.info('File has TIFF thumbnail')
|
| 110 |
+
del data['TIFFThumbnail']
|
| 111 |
+
|
| 112 |
+
tag_keys = list(data.keys())
|
| 113 |
+
tag_keys.sort()
|
| 114 |
+
|
| 115 |
+
for i in tag_keys:
|
| 116 |
+
try:
|
| 117 |
+
logger.info('%s (%s): %s', i, FIELD_TYPES[data[i].field_type][2], data[i].printable)
|
| 118 |
+
except:
|
| 119 |
+
logger.error("%s : %s", i, str(data[i]))
|
| 120 |
+
|
| 121 |
+
file_stop = timeit.default_timer()
|
| 122 |
+
|
| 123 |
+
logger.debug("Tags processed in %s seconds", tag_stop - tag_start)
|
| 124 |
+
logger.debug("File processed in %s seconds", file_stop - file_start)
|
| 125 |
+
print("")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == '__main__':
|
| 129 |
+
main()
|
spiderfoot/venv-spiderfoot/Scripts/activate
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file must be used with "source bin/activate" *from bash*
|
| 2 |
+
# you cannot run it directly
|
| 3 |
+
|
| 4 |
+
deactivate () {
|
| 5 |
+
# reset old environment variables
|
| 6 |
+
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
| 7 |
+
PATH="${_OLD_VIRTUAL_PATH:-}"
|
| 8 |
+
export PATH
|
| 9 |
+
unset _OLD_VIRTUAL_PATH
|
| 10 |
+
fi
|
| 11 |
+
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
| 12 |
+
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
| 13 |
+
export PYTHONHOME
|
| 14 |
+
unset _OLD_VIRTUAL_PYTHONHOME
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
# This should detect bash and zsh, which have a hash command that must
|
| 18 |
+
# be called to get it to forget past commands. Without forgetting
|
| 19 |
+
# past commands the $PATH changes we made may not be respected
|
| 20 |
+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
| 21 |
+
hash -r 2> /dev/null
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
| 25 |
+
PS1="${_OLD_VIRTUAL_PS1:-}"
|
| 26 |
+
export PS1
|
| 27 |
+
unset _OLD_VIRTUAL_PS1
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
unset VIRTUAL_ENV
|
| 31 |
+
unset VIRTUAL_ENV_PROMPT
|
| 32 |
+
if [ ! "${1:-}" = "nondestructive" ] ; then
|
| 33 |
+
# Self destruct!
|
| 34 |
+
unset -f deactivate
|
| 35 |
+
fi
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
# unset irrelevant variables
|
| 39 |
+
deactivate nondestructive
|
| 40 |
+
|
| 41 |
+
VIRTUAL_ENV="c:\Ba7ath_project\dashboard_osint\spiderfoot\venv-spiderfoot"
|
| 42 |
+
export VIRTUAL_ENV
|
| 43 |
+
|
| 44 |
+
_OLD_VIRTUAL_PATH="$PATH"
|
| 45 |
+
PATH="$VIRTUAL_ENV/Scripts:$PATH"
|
| 46 |
+
export PATH
|
| 47 |
+
|
| 48 |
+
# unset PYTHONHOME if set
|
| 49 |
+
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
| 50 |
+
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
| 51 |
+
if [ -n "${PYTHONHOME:-}" ] ; then
|
| 52 |
+
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
| 53 |
+
unset PYTHONHOME
|
| 54 |
+
fi
|
| 55 |
+
|
| 56 |
+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
| 57 |
+
_OLD_VIRTUAL_PS1="${PS1:-}"
|
| 58 |
+
PS1="(venv-spiderfoot) ${PS1:-}"
|
| 59 |
+
export PS1
|
| 60 |
+
VIRTUAL_ENV_PROMPT="(venv-spiderfoot) "
|
| 61 |
+
export VIRTUAL_ENV_PROMPT
|
| 62 |
+
fi
|
| 63 |
+
|
| 64 |
+
# This should detect bash and zsh, which have a hash command that must
|
| 65 |
+
# be called to get it to forget past commands. Without forgetting
|
| 66 |
+
# past commands the $PATH changes we made may not be respected
|
| 67 |
+
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
|
| 68 |
+
hash -r 2> /dev/null
|
| 69 |
+
fi
|
spiderfoot/venv-spiderfoot/Scripts/activate.bat
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
|
| 3 |
+
rem This file is UTF-8 encoded, so we need to update the current code page while executing it
|
| 4 |
+
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
|
| 5 |
+
set _OLD_CODEPAGE=%%a
|
| 6 |
+
)
|
| 7 |
+
if defined _OLD_CODEPAGE (
|
| 8 |
+
"%SystemRoot%\System32\chcp.com" 65001 > nul
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
set VIRTUAL_ENV=c:\Ba7ath_project\dashboard_osint\spiderfoot\venv-spiderfoot
|
| 12 |
+
|
| 13 |
+
if not defined PROMPT set PROMPT=$P$G
|
| 14 |
+
|
| 15 |
+
if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
|
| 16 |
+
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%
|
| 17 |
+
|
| 18 |
+
set _OLD_VIRTUAL_PROMPT=%PROMPT%
|
| 19 |
+
set PROMPT=(venv-spiderfoot) %PROMPT%
|
| 20 |
+
|
| 21 |
+
if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
|
| 22 |
+
set PYTHONHOME=
|
| 23 |
+
|
| 24 |
+
if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
|
| 25 |
+
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%
|
| 26 |
+
|
| 27 |
+
set PATH=%VIRTUAL_ENV%\Scripts;%PATH%
|
| 28 |
+
set VIRTUAL_ENV_PROMPT=(venv-spiderfoot)
|
| 29 |
+
|
| 30 |
+
:END
|
| 31 |
+
if defined _OLD_CODEPAGE (
|
| 32 |
+
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
|
| 33 |
+
set _OLD_CODEPAGE=
|
| 34 |
+
)
|
spiderfoot/venv-spiderfoot/Scripts/deactivate.bat
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@echo off
|
| 2 |
+
|
| 3 |
+
if defined _OLD_VIRTUAL_PROMPT (
|
| 4 |
+
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
|
| 5 |
+
)
|
| 6 |
+
set _OLD_VIRTUAL_PROMPT=
|
| 7 |
+
|
| 8 |
+
if defined _OLD_VIRTUAL_PYTHONHOME (
|
| 9 |
+
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2013-2019 Philip Hane
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Redistribution and use in source and binary forms, with or without
|
| 5 |
+
# modification, are permitted provided that the following conditions are met:
|
| 6 |
+
#
|
| 7 |
+
# 1. Redistributions of source code must retain the above copyright notice,
|
| 8 |
+
# this list of conditions and the following disclaimer.
|
| 9 |
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 10 |
+
# this list of conditions and the following disclaimer in the documentation
|
| 11 |
+
# and/or other materials provided with the distribution.
|
| 12 |
+
#
|
| 13 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 17 |
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 18 |
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 19 |
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 20 |
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 21 |
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 22 |
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 23 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
|
| 25 |
+
# CLI python script interface for ipwhois.IPWhois lookups.
|
| 26 |
+
|
| 27 |
+
import argparse
|
| 28 |
+
import json
|
| 29 |
+
from os import path
|
| 30 |
+
from ipwhois import IPWhois
|
| 31 |
+
from ipwhois.hr import (HR_ASN, HR_RDAP, HR_RDAP_COMMON, HR_WHOIS,
|
| 32 |
+
HR_WHOIS_NIR)
|
| 33 |
+
|
| 34 |
+
try: # pragma: no cover
|
| 35 |
+
from urllib.request import (ProxyHandler,
|
| 36 |
+
build_opener)
|
| 37 |
+
except ImportError: # pragma: no cover
|
| 38 |
+
from urllib2 import (ProxyHandler,
|
| 39 |
+
build_opener)
|
| 40 |
+
|
| 41 |
+
# CLI ANSI rendering
|
| 42 |
+
ANSI = {
|
| 43 |
+
'end': '\033[0m',
|
| 44 |
+
'b': '\033[1m',
|
| 45 |
+
'ul': '\033[4m',
|
| 46 |
+
'red': '\033[31m',
|
| 47 |
+
'green': '\033[32m',
|
| 48 |
+
'yellow': '\033[33m',
|
| 49 |
+
'cyan': '\033[36m'
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
# Color definitions for sub lines
|
| 53 |
+
COLOR_DEPTH = {
|
| 54 |
+
'0': ANSI['green'],
|
| 55 |
+
'1': ANSI['yellow'],
|
| 56 |
+
'2': ANSI['red'],
|
| 57 |
+
'3': ANSI['cyan']
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
# Line formatting, keys ending in C are colorized versions.
|
| 61 |
+
LINES = {
|
| 62 |
+
'1': '>> ',
|
| 63 |
+
'2': '>> >>> ',
|
| 64 |
+
'3': '>> >>> >>>> ',
|
| 65 |
+
'4': '>> >>> >>>> >>>>> ',
|
| 66 |
+
'1C': '{0}>>{1} '.format(COLOR_DEPTH['0'], ANSI['end']),
|
| 67 |
+
'2C': '{0}>>{1} >>>{2} '.format(
|
| 68 |
+
COLOR_DEPTH['0'], COLOR_DEPTH['1'], ANSI['end']
|
| 69 |
+
),
|
| 70 |
+
'3C': '{0}>>{1} >>>{2} >>>>{3} '.format(
|
| 71 |
+
COLOR_DEPTH['0'], COLOR_DEPTH['1'], COLOR_DEPTH['2'], ANSI['end']
|
| 72 |
+
),
|
| 73 |
+
'4C': '{0}>>{1} >>>{2} >>>>{3} >>>>>{4} '.format(
|
| 74 |
+
COLOR_DEPTH['0'], COLOR_DEPTH['1'], COLOR_DEPTH['2'], COLOR_DEPTH['3'],
|
| 75 |
+
ANSI['end']
|
| 76 |
+
),
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
# Setup the arg parser.
|
| 80 |
+
parser = argparse.ArgumentParser(
|
| 81 |
+
description='ipwhois CLI interface'
|
| 82 |
+
)
|
| 83 |
+
parser.add_argument(
|
| 84 |
+
'--whois',
|
| 85 |
+
action='store_true',
|
| 86 |
+
help='Retrieve whois data via legacy Whois (port 43) instead of RDAP '
|
| 87 |
+
'(default).'
|
| 88 |
+
)
|
| 89 |
+
parser.add_argument(
|
| 90 |
+
'--exclude_nir',
|
| 91 |
+
action='store_true',
|
| 92 |
+
help='Disable NIR whois lookups (JPNIC, KRNIC). This is the opposite of '
|
| 93 |
+
'the ipwhois inc_nir, in order to enable inc_nir by default in the '
|
| 94 |
+
'CLI.',
|
| 95 |
+
default=False
|
| 96 |
+
)
|
| 97 |
+
parser.add_argument(
|
| 98 |
+
'--json',
|
| 99 |
+
action='store_true',
|
| 100 |
+
help='Output results in JSON format.',
|
| 101 |
+
default=False
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# Output options
|
| 105 |
+
group = parser.add_argument_group('Output options')
|
| 106 |
+
group.add_argument(
|
| 107 |
+
'--hr',
|
| 108 |
+
action='store_true',
|
| 109 |
+
help='If set, returns results with human readable key translations.'
|
| 110 |
+
)
|
| 111 |
+
group.add_argument(
|
| 112 |
+
'--show_name',
|
| 113 |
+
action='store_true',
|
| 114 |
+
help='If this and --hr are set, the key name is shown in parentheses after'
|
| 115 |
+
'its short value'
|
| 116 |
+
)
|
| 117 |
+
group.add_argument(
|
| 118 |
+
'--colorize',
|
| 119 |
+
action='store_true',
|
| 120 |
+
help='If set, colorizes the output using ANSI. Should work in most '
|
| 121 |
+
'platform consoles.'
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# IPWhois settings (common)
|
| 125 |
+
group = parser.add_argument_group('IPWhois settings')
|
| 126 |
+
group.add_argument(
|
| 127 |
+
'--timeout',
|
| 128 |
+
type=int,
|
| 129 |
+
default=5,
|
| 130 |
+
metavar='TIMEOUT',
|
| 131 |
+
help='The default timeout for socket connections in seconds.'
|
| 132 |
+
)
|
| 133 |
+
group.add_argument(
|
| 134 |
+
'--proxy_http',
|
| 135 |
+
type=str,
|
| 136 |
+
nargs=1,
|
| 137 |
+
default='',
|
| 138 |
+
metavar='"PROXY_HTTP"',
|
| 139 |
+
help='The proxy HTTP address passed to request.ProxyHandler. User auth '
|
| 140 |
+
'can be passed like "http://user:pass@192.168.0.1:80"',
|
| 141 |
+
required=False
|
| 142 |
+
)
|
| 143 |
+
group.add_argument(
|
| 144 |
+
'--proxy_https',
|
| 145 |
+
type=str,
|
| 146 |
+
nargs=1,
|
| 147 |
+
default='',
|
| 148 |
+
metavar='"PROXY_HTTPS"',
|
| 149 |
+
help='The proxy HTTPS address passed to request.ProxyHandler. User auth'
|
| 150 |
+
'can be passed like "https://user:pass@192.168.0.1:443"',
|
| 151 |
+
required=False
|
| 152 |
+
)
|
| 153 |
+
group.add_argument(
|
| 154 |
+
'--disallow_permutations',
|
| 155 |
+
action='store_true',
|
| 156 |
+
help='Disable additional methods if DNS lookups to Cymru fail. This is the'
|
| 157 |
+
' opposite of the ipwhois allow_permutations, in order to enable '
|
| 158 |
+
'allow_permutations by default in the CLI. *WARNING* deprecated in '
|
| 159 |
+
'favor of new argument asn_methods.',
|
| 160 |
+
default=False
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
# Common (RDAP & Legacy Whois)
|
| 164 |
+
group = parser.add_argument_group('Common settings (RDAP & Legacy Whois)')
|
| 165 |
+
group.add_argument(
|
| 166 |
+
'--inc_raw',
|
| 167 |
+
action='store_true',
|
| 168 |
+
help='Include the raw whois results in the output.'
|
| 169 |
+
)
|
| 170 |
+
group.add_argument(
|
| 171 |
+
'--retry_count',
|
| 172 |
+
type=int,
|
| 173 |
+
default=3,
|
| 174 |
+
metavar='RETRY_COUNT',
|
| 175 |
+
help='The number of times to retry in case socket errors, timeouts, '
|
| 176 |
+
'connection resets, etc. are encountered.'
|
| 177 |
+
)
|
| 178 |
+
group.add_argument(
|
| 179 |
+
'--asn_alts',
|
| 180 |
+
type=str,
|
| 181 |
+
nargs=1,
|
| 182 |
+
default='whois,http',
|
| 183 |
+
metavar='"ASN_ALTS"',
|
| 184 |
+
help='A comma delimited list of additional lookup types to attempt if the '
|
| 185 |
+
'ASN dns lookup fails. Allow permutations must be enabled. '
|
| 186 |
+
'Defaults to all: "whois,http" *WARNING* deprecated in '
|
| 187 |
+
'favor of new argument asn_methods.'
|
| 188 |
+
)
|
| 189 |
+
group.add_argument(
|
| 190 |
+
'--asn_methods',
|
| 191 |
+
type=str,
|
| 192 |
+
nargs=1,
|
| 193 |
+
default='dns,whois,http',
|
| 194 |
+
metavar='"ASN_METHODS"',
|
| 195 |
+
help='List of ASN lookup types to attempt, in order. '
|
| 196 |
+
'Defaults to all [\'dns\', \'whois\', \'http\'].'
|
| 197 |
+
)
|
| 198 |
+
group.add_argument(
|
| 199 |
+
'--extra_org_map',
|
| 200 |
+
type=json.loads,
|
| 201 |
+
nargs=1,
|
| 202 |
+
default='{"DNIC": "arin"}',
|
| 203 |
+
metavar='"EXTRA_ORG_MAP"',
|
| 204 |
+
help='Dictionary mapping org handles to RIRs. This is for limited cases '
|
| 205 |
+
'where ARIN REST (ASN fallback HTTP lookup) does not show an RIR as '
|
| 206 |
+
'the org handle e.g., DNIC (which is now the built in ORG_MAP) e.g., '
|
| 207 |
+
'{\\"DNIC\\": \\"arin\\"}. Valid RIR values are (note the '
|
| 208 |
+
'case-sensitive - this is meant to match the REST result): '
|
| 209 |
+
'\'ARIN\', \'RIPE\', \'apnic\', \'lacnic\', \'afrinic\''
|
| 210 |
+
)
|
| 211 |
+
group.add_argument(
|
| 212 |
+
'--skip_asn_description',
|
| 213 |
+
action='store_true',
|
| 214 |
+
help='Don\'t run an additional query when pulling ASN information via dns '
|
| 215 |
+
'(to get the ASN description). This is the opposite of the ipwhois '
|
| 216 |
+
'get_asn_description argument, in order to enable '
|
| 217 |
+
'get_asn_description by default in the CLI.',
|
| 218 |
+
default=False
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
# RDAP
|
| 222 |
+
group = parser.add_argument_group('RDAP settings')
|
| 223 |
+
group.add_argument(
|
| 224 |
+
'--depth',
|
| 225 |
+
type=int,
|
| 226 |
+
default=0,
|
| 227 |
+
metavar='COLOR_DEPTH',
|
| 228 |
+
help='If not --whois, how many levels deep to run RDAP queries when '
|
| 229 |
+
'additional referenced objects are found.'
|
| 230 |
+
)
|
| 231 |
+
group.add_argument(
|
| 232 |
+
'--excluded_entities',
|
| 233 |
+
type=str,
|
| 234 |
+
nargs=1,
|
| 235 |
+
default=None,
|
| 236 |
+
metavar='"EXCLUDED_ENTITIES"',
|
| 237 |
+
help='If not --whois, a comma delimited list of entity handles to not '
|
| 238 |
+
'perform lookups.'
|
| 239 |
+
)
|
| 240 |
+
group.add_argument(
|
| 241 |
+
'--bootstrap',
|
| 242 |
+
action='store_true',
|
| 243 |
+
help='If not --whois, performs lookups via ARIN bootstrap rather than '
|
| 244 |
+
'lookups based on ASN data. ASN lookups are not performed and no '
|
| 245 |
+
'output for any of the asn* fields is provided.'
|
| 246 |
+
)
|
| 247 |
+
group.add_argument(
|
| 248 |
+
'--rate_limit_timeout',
|
| 249 |
+
type=int,
|
| 250 |
+
default=120,
|
| 251 |
+
metavar='RATE_LIMIT_TIMEOUT',
|
| 252 |
+
help='If not --whois, the number of seconds to wait before retrying when '
|
| 253 |
+
'a rate limit notice is returned via rdap+json.'
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
# Legacy Whois
|
| 257 |
+
group = parser.add_argument_group('Legacy Whois settings')
|
| 258 |
+
group.add_argument(
|
| 259 |
+
'--get_referral',
|
| 260 |
+
action='store_true',
|
| 261 |
+
help='If --whois, retrieve referral whois information, if available.'
|
| 262 |
+
)
|
| 263 |
+
group.add_argument(
|
| 264 |
+
'--extra_blacklist',
|
| 265 |
+
type=str,
|
| 266 |
+
nargs=1,
|
| 267 |
+
default='',
|
| 268 |
+
metavar='"EXTRA_BLACKLIST"',
|
| 269 |
+
help='If --whois, A list of blacklisted whois servers in addition to the '
|
| 270 |
+
'global BLACKLIST.'
|
| 271 |
+
)
|
| 272 |
+
group.add_argument(
|
| 273 |
+
'--ignore_referral_errors',
|
| 274 |
+
action='store_true',
|
| 275 |
+
help='If --whois, ignore and continue when an exception is encountered on '
|
| 276 |
+
'referral whois lookups.'
|
| 277 |
+
)
|
| 278 |
+
group.add_argument(
|
| 279 |
+
'--field_list',
|
| 280 |
+
type=str,
|
| 281 |
+
nargs=1,
|
| 282 |
+
default='',
|
| 283 |
+
metavar='"FIELD_LIST"',
|
| 284 |
+
help='If --whois, a list of fields to parse: '
|
| 285 |
+
'[\'name\', \'handle\', \'description\', \'country\', \'state\', '
|
| 286 |
+
'\'city\', \'address\', \'postal_code\', \'emails\', \'created\', '
|
| 287 |
+
'\'updated\']'
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
# NIR (National Internet Registry -- JPNIC, KRNIC)
|
| 291 |
+
group = parser.add_argument_group('NIR (National Internet Registry) settings')
|
| 292 |
+
group.add_argument(
|
| 293 |
+
'--nir_field_list',
|
| 294 |
+
type=str,
|
| 295 |
+
nargs=1,
|
| 296 |
+
default='',
|
| 297 |
+
metavar='"NIR_FIELD_LIST"',
|
| 298 |
+
help='If not --exclude_nir, a list of fields to parse: '
|
| 299 |
+
'[\'name\', \'handle\', \'country\', \'address\', \'postal_code\', '
|
| 300 |
+
'\'nameservers\', \'created\', \'updated\', \'contact_admin\', '
|
| 301 |
+
'\'contact_tech\']'
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
+
# Input (required)
|
| 305 |
+
group = parser.add_argument_group('Input (Required)')
|
| 306 |
+
group.add_argument(
|
| 307 |
+
'--addr',
|
| 308 |
+
type=str,
|
| 309 |
+
nargs=1,
|
| 310 |
+
metavar='"IP"',
|
| 311 |
+
help='An IPv4 or IPv6 address as a string.',
|
| 312 |
+
required=True
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
# Get the args
|
| 316 |
+
script_args = parser.parse_args()
|
| 317 |
+
|
| 318 |
+
# Get the current working directory.
|
| 319 |
+
CUR_DIR = path.dirname(__file__)
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def generate_output(line='0', short=None, name=None, value=None,
|
| 323 |
+
is_parent=False, colorize=True):
|
| 324 |
+
"""
|
| 325 |
+
The function for formatting CLI output results.
|
| 326 |
+
|
| 327 |
+
Args:
|
| 328 |
+
line (:obj:`str`): The line number (0-4). Determines indentation.
|
| 329 |
+
Defaults to '0'.
|
| 330 |
+
short (:obj:`str`): The optional abbreviated name for a field.
|
| 331 |
+
See hr.py for values.
|
| 332 |
+
name (:obj:`str`): The optional name for a field. See hr.py for values.
|
| 333 |
+
value (:obj:`str`): The field data (required).
|
| 334 |
+
is_parent (:obj:`bool`): Set to True if the field value has sub-items
|
| 335 |
+
(dicts/lists). Defaults to False.
|
| 336 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI colors.
|
| 337 |
+
Defaults to True.
|
| 338 |
+
|
| 339 |
+
Returns:
|
| 340 |
+
str: The generated output.
|
| 341 |
+
"""
|
| 342 |
+
|
| 343 |
+
# TODO: so ugly
|
| 344 |
+
output = '{0}{1}{2}{3}{4}{5}{6}{7}\n'.format(
|
| 345 |
+
LINES['{0}{1}'.format(line, 'C' if colorize else '')] if (
|
| 346 |
+
line in LINES.keys()) else '',
|
| 347 |
+
COLOR_DEPTH[line] if (colorize and line in COLOR_DEPTH) else '',
|
| 348 |
+
ANSI['b'],
|
| 349 |
+
short if short is not None else (
|
| 350 |
+
name if (name is not None) else ''
|
| 351 |
+
),
|
| 352 |
+
'' if (name is None or short is None) else ' ({0})'.format(
|
| 353 |
+
name),
|
| 354 |
+
'' if (name is None and short is None) else ': ',
|
| 355 |
+
ANSI['end'] if colorize else '',
|
| 356 |
+
'' if is_parent else value
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
return output
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class IPWhoisCLI:
|
| 363 |
+
"""
|
| 364 |
+
The CLI wrapper class for outputting formatted IPWhois results.
|
| 365 |
+
|
| 366 |
+
Args:
|
| 367 |
+
addr (:obj:`str`/:obj:`int`/:obj:`IPv4Address`/:obj:`IPv6Address`):
|
| 368 |
+
An IPv4 or IPv6 address
|
| 369 |
+
timeout (:obj:`int`): The default timeout for socket connections in
|
| 370 |
+
seconds. Defaults to 5.
|
| 371 |
+
proxy_http (:obj:`urllib.request.OpenerDirector`): The request for
|
| 372 |
+
proxy HTTP support or None.
|
| 373 |
+
proxy_https (:obj:`urllib.request.OpenerDirector`): The request for
|
| 374 |
+
proxy HTTPS support or None.
|
| 375 |
+
allow_permutations (:obj:`bool`): Allow net.Net() to use additional
|
| 376 |
+
methods if DNS lookups to Cymru fail. *WARNING* deprecated in
|
| 377 |
+
favor of new argument asn_methods. Defaults to True.
|
| 378 |
+
"""
|
| 379 |
+
|
| 380 |
+
def __init__(
|
| 381 |
+
self,
|
| 382 |
+
addr,
|
| 383 |
+
timeout,
|
| 384 |
+
proxy_http,
|
| 385 |
+
proxy_https,
|
| 386 |
+
allow_permutations
|
| 387 |
+
):
|
| 388 |
+
|
| 389 |
+
self.addr = addr
|
| 390 |
+
self.timeout = timeout
|
| 391 |
+
|
| 392 |
+
handler_dict = None
|
| 393 |
+
if proxy_http is not None:
|
| 394 |
+
|
| 395 |
+
handler_dict = {'http': proxy_http}
|
| 396 |
+
|
| 397 |
+
if proxy_https is not None:
|
| 398 |
+
|
| 399 |
+
if handler_dict is None:
|
| 400 |
+
|
| 401 |
+
handler_dict = {'https': proxy_https}
|
| 402 |
+
|
| 403 |
+
else:
|
| 404 |
+
|
| 405 |
+
handler_dict['https'] = proxy_https
|
| 406 |
+
|
| 407 |
+
if handler_dict is None:
|
| 408 |
+
|
| 409 |
+
self.opener = None
|
| 410 |
+
else:
|
| 411 |
+
|
| 412 |
+
handler = ProxyHandler(handler_dict)
|
| 413 |
+
self.opener = build_opener(handler)
|
| 414 |
+
|
| 415 |
+
self.allow_permutations = allow_permutations
|
| 416 |
+
|
| 417 |
+
self.obj = IPWhois(address=self.addr,
|
| 418 |
+
timeout=self.timeout,
|
| 419 |
+
proxy_opener=self.opener,
|
| 420 |
+
allow_permutations=self.allow_permutations)
|
| 421 |
+
|
| 422 |
+
def generate_output_header(self, query_type='RDAP'):
|
| 423 |
+
"""
|
| 424 |
+
The function for generating the CLI output header.
|
| 425 |
+
|
| 426 |
+
Args:
|
| 427 |
+
query_type (:obj:`str`): The IPWhois query type. Defaults to
|
| 428 |
+
'RDAP'.
|
| 429 |
+
|
| 430 |
+
Returns:
|
| 431 |
+
str: The generated output.
|
| 432 |
+
"""
|
| 433 |
+
|
| 434 |
+
output = '\n{0}{1}{2} query for {3}:{4}\n\n'.format(
|
| 435 |
+
ANSI['ul'],
|
| 436 |
+
ANSI['b'],
|
| 437 |
+
query_type,
|
| 438 |
+
self.obj.address_str,
|
| 439 |
+
ANSI['end']
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
return output
|
| 443 |
+
|
| 444 |
+
def generate_output_newline(self, line='0', colorize=True):
|
| 445 |
+
"""
|
| 446 |
+
The function for generating a CLI output new line.
|
| 447 |
+
|
| 448 |
+
Args:
|
| 449 |
+
line (:obj:`str`): The line number (0-4). Determines indentation.
|
| 450 |
+
Defaults to '0'.
|
| 451 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 452 |
+
colors. Defaults to True.
|
| 453 |
+
|
| 454 |
+
Returns:
|
| 455 |
+
str: The generated output.
|
| 456 |
+
"""
|
| 457 |
+
|
| 458 |
+
return generate_output(
|
| 459 |
+
line=line,
|
| 460 |
+
is_parent=True,
|
| 461 |
+
colorize=colorize
|
| 462 |
+
)
|
| 463 |
+
|
| 464 |
+
def generate_output_asn(self, json_data=None, hr=True, show_name=False,
|
| 465 |
+
colorize=True):
|
| 466 |
+
"""
|
| 467 |
+
The function for generating CLI output ASN results.
|
| 468 |
+
|
| 469 |
+
Args:
|
| 470 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 471 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 472 |
+
to True.
|
| 473 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 474 |
+
only show short). Defaults to False.
|
| 475 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 476 |
+
colors. Defaults to True.
|
| 477 |
+
|
| 478 |
+
Returns:
|
| 479 |
+
str: The generated output.
|
| 480 |
+
"""
|
| 481 |
+
|
| 482 |
+
if json_data is None:
|
| 483 |
+
json_data = {}
|
| 484 |
+
|
| 485 |
+
keys = {'asn', 'asn_cidr', 'asn_country_code', 'asn_date',
|
| 486 |
+
'asn_registry', 'asn_description'}.intersection(json_data)
|
| 487 |
+
|
| 488 |
+
output = ''
|
| 489 |
+
|
| 490 |
+
for key in keys:
|
| 491 |
+
|
| 492 |
+
output += generate_output(
|
| 493 |
+
line='0',
|
| 494 |
+
short=HR_ASN[key]['_short'] if hr else key,
|
| 495 |
+
name=HR_ASN[key]['_name'] if (hr and show_name) else None,
|
| 496 |
+
value=(json_data[key] if (
|
| 497 |
+
json_data[key] is not None and
|
| 498 |
+
len(json_data[key]) > 0 and
|
| 499 |
+
json_data[key] != 'NA') else 'None'),
|
| 500 |
+
colorize=colorize
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
return output
|
| 504 |
+
|
| 505 |
+
def generate_output_entities(self, json_data=None, hr=True,
|
| 506 |
+
show_name=False, colorize=True):
|
| 507 |
+
"""
|
| 508 |
+
The function for generating CLI output RDAP entity results.
|
| 509 |
+
|
| 510 |
+
Args:
|
| 511 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 512 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 513 |
+
to True.
|
| 514 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 515 |
+
only show short). Defaults to False.
|
| 516 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 517 |
+
colors. Defaults to True.
|
| 518 |
+
|
| 519 |
+
Returns:
|
| 520 |
+
str: The generated output.
|
| 521 |
+
"""
|
| 522 |
+
|
| 523 |
+
output = ''
|
| 524 |
+
short = HR_RDAP['entities']['_short'] if hr else 'entities'
|
| 525 |
+
name = HR_RDAP['entities']['_name'] if (hr and show_name) else None
|
| 526 |
+
|
| 527 |
+
output += generate_output(
|
| 528 |
+
line='0',
|
| 529 |
+
short=short,
|
| 530 |
+
name=name,
|
| 531 |
+
is_parent=False if (json_data is None or
|
| 532 |
+
json_data['entities'] is None) else True,
|
| 533 |
+
value='None' if (json_data is None or
|
| 534 |
+
json_data['entities'] is None) else None,
|
| 535 |
+
colorize=colorize
|
| 536 |
+
)
|
| 537 |
+
|
| 538 |
+
if json_data is not None:
|
| 539 |
+
|
| 540 |
+
for ent in json_data['entities']:
|
| 541 |
+
|
| 542 |
+
output += generate_output(
|
| 543 |
+
line='1',
|
| 544 |
+
value=ent,
|
| 545 |
+
colorize=colorize
|
| 546 |
+
)
|
| 547 |
+
|
| 548 |
+
return output
|
| 549 |
+
|
| 550 |
+
def generate_output_events(self, source, key, val, line='2', hr=True,
|
| 551 |
+
show_name=False, colorize=True):
|
| 552 |
+
"""
|
| 553 |
+
The function for generating CLI output RDAP events results.
|
| 554 |
+
|
| 555 |
+
Args:
|
| 556 |
+
source (:obj:`str`): The parent key 'network' or 'objects'
|
| 557 |
+
(required).
|
| 558 |
+
key (:obj:`str`): The event key 'events' or 'events_actor'
|
| 559 |
+
(required).
|
| 560 |
+
val (:obj:`dict`): The event dictionary (required).
|
| 561 |
+
line (:obj:`str`): The line number (0-4). Determines indentation.
|
| 562 |
+
Defaults to '0'.
|
| 563 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 564 |
+
to True.
|
| 565 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 566 |
+
only show short). Defaults to False.
|
| 567 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 568 |
+
colors. Defaults to True.
|
| 569 |
+
|
| 570 |
+
Returns:
|
| 571 |
+
str: The generated output.
|
| 572 |
+
"""
|
| 573 |
+
|
| 574 |
+
output = generate_output(
|
| 575 |
+
line=line,
|
| 576 |
+
short=HR_RDAP[source][key]['_short'] if hr else key,
|
| 577 |
+
name=HR_RDAP[source][key]['_name'] if (hr and show_name) else None,
|
| 578 |
+
is_parent=False if (val is None or
|
| 579 |
+
len(val) == 0) else True,
|
| 580 |
+
value='None' if (val is None or
|
| 581 |
+
len(val) == 0) else None,
|
| 582 |
+
colorize=colorize
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
if val is not None:
|
| 586 |
+
|
| 587 |
+
count = 0
|
| 588 |
+
for item in val:
|
| 589 |
+
|
| 590 |
+
try:
|
| 591 |
+
action = item['action']
|
| 592 |
+
except KeyError:
|
| 593 |
+
action = None
|
| 594 |
+
|
| 595 |
+
try:
|
| 596 |
+
timestamp = item['timestamp']
|
| 597 |
+
except KeyError:
|
| 598 |
+
timestamp = None
|
| 599 |
+
|
| 600 |
+
try:
|
| 601 |
+
actor = item['actor']
|
| 602 |
+
except KeyError:
|
| 603 |
+
actor = None
|
| 604 |
+
|
| 605 |
+
if count > 0:
|
| 606 |
+
output += generate_output(
|
| 607 |
+
line=str(int(line)+1),
|
| 608 |
+
is_parent=True,
|
| 609 |
+
colorize=colorize
|
| 610 |
+
)
|
| 611 |
+
|
| 612 |
+
output += generate_output(
|
| 613 |
+
line=str(int(line)+1),
|
| 614 |
+
short=HR_RDAP_COMMON[key]['action'][
|
| 615 |
+
'_short'] if hr else 'action',
|
| 616 |
+
name=HR_RDAP_COMMON[key]['action'][
|
| 617 |
+
'_name'] if (hr and show_name) else None,
|
| 618 |
+
value=action,
|
| 619 |
+
colorize=colorize
|
| 620 |
+
)
|
| 621 |
+
|
| 622 |
+
output += generate_output(
|
| 623 |
+
line=str(int(line)+1),
|
| 624 |
+
short=HR_RDAP_COMMON[key]['timestamp'][
|
| 625 |
+
'_short'] if hr else 'timestamp',
|
| 626 |
+
name=HR_RDAP_COMMON[key]['timestamp'][
|
| 627 |
+
'_name'] if (hr and show_name) else None,
|
| 628 |
+
value=timestamp,
|
| 629 |
+
colorize=colorize
|
| 630 |
+
)
|
| 631 |
+
|
| 632 |
+
output += generate_output(
|
| 633 |
+
line=str(int(line)+1),
|
| 634 |
+
short=HR_RDAP_COMMON[key]['actor'][
|
| 635 |
+
'_short'] if hr else 'actor',
|
| 636 |
+
name=HR_RDAP_COMMON[key]['actor'][
|
| 637 |
+
'_name'] if (hr and show_name) else None,
|
| 638 |
+
value=actor,
|
| 639 |
+
colorize=colorize
|
| 640 |
+
)
|
| 641 |
+
|
| 642 |
+
count += 1
|
| 643 |
+
|
| 644 |
+
return output
|
| 645 |
+
|
| 646 |
+
def generate_output_list(self, source, key, val, line='2', hr=True,
|
| 647 |
+
show_name=False, colorize=True):
|
| 648 |
+
"""
|
| 649 |
+
The function for generating CLI output RDAP list results.
|
| 650 |
+
|
| 651 |
+
Args:
|
| 652 |
+
source (:obj:`str`): The parent key 'network' or 'objects'
|
| 653 |
+
(required).
|
| 654 |
+
key (:obj:`str`): The event key 'events' or 'events_actor'
|
| 655 |
+
(required).
|
| 656 |
+
val (:obj:`dict`): The event dictionary (required).
|
| 657 |
+
line (:obj:`str`): The line number (0-4). Determines indentation.
|
| 658 |
+
Defaults to '0'.
|
| 659 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 660 |
+
to True.
|
| 661 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 662 |
+
only show short). Defaults to False.
|
| 663 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 664 |
+
colors. Defaults to True.
|
| 665 |
+
|
| 666 |
+
Returns:
|
| 667 |
+
str: The generated output.
|
| 668 |
+
"""
|
| 669 |
+
|
| 670 |
+
output = generate_output(
|
| 671 |
+
line=line,
|
| 672 |
+
short=HR_RDAP[source][key]['_short'] if hr else key,
|
| 673 |
+
name=HR_RDAP[source][key]['_name'] if (hr and show_name) else None,
|
| 674 |
+
is_parent=False if (val is None or
|
| 675 |
+
len(val) == 0) else True,
|
| 676 |
+
value='None' if (val is None or
|
| 677 |
+
len(val) == 0) else None,
|
| 678 |
+
colorize=colorize
|
| 679 |
+
)
|
| 680 |
+
|
| 681 |
+
if val is not None:
|
| 682 |
+
for item in val:
|
| 683 |
+
output += generate_output(
|
| 684 |
+
line=str(int(line)+1),
|
| 685 |
+
value=item,
|
| 686 |
+
colorize=colorize
|
| 687 |
+
)
|
| 688 |
+
|
| 689 |
+
return output
|
| 690 |
+
|
| 691 |
+
def generate_output_notices(self, source, key, val, line='1', hr=True,
|
| 692 |
+
show_name=False, colorize=True):
|
| 693 |
+
"""
|
| 694 |
+
The function for generating CLI output RDAP notices results.
|
| 695 |
+
|
| 696 |
+
Args:
|
| 697 |
+
source (:obj:`str`): The parent key 'network' or 'objects'
|
| 698 |
+
(required).
|
| 699 |
+
key (:obj:`str`): The event key 'events' or 'events_actor'
|
| 700 |
+
(required).
|
| 701 |
+
val (:obj:`dict`): The event dictionary (required).
|
| 702 |
+
line (:obj:`str`): The line number (0-4). Determines indentation.
|
| 703 |
+
Defaults to '0'.
|
| 704 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 705 |
+
to True.
|
| 706 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 707 |
+
only show short). Defaults to False.
|
| 708 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 709 |
+
colors. Defaults to True.
|
| 710 |
+
|
| 711 |
+
Returns:
|
| 712 |
+
str: The generated output.
|
| 713 |
+
"""
|
| 714 |
+
|
| 715 |
+
output = generate_output(
|
| 716 |
+
line=line,
|
| 717 |
+
short=HR_RDAP[source][key]['_short'] if hr else key,
|
| 718 |
+
name=HR_RDAP[source][key]['_name'] if (hr and show_name) else None,
|
| 719 |
+
is_parent=False if (val is None or
|
| 720 |
+
len(val) == 0) else True,
|
| 721 |
+
value='None' if (val is None or
|
| 722 |
+
len(val) == 0) else None,
|
| 723 |
+
colorize=colorize
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
if val is not None:
|
| 727 |
+
|
| 728 |
+
count = 0
|
| 729 |
+
for item in val:
|
| 730 |
+
|
| 731 |
+
title = item['title']
|
| 732 |
+
description = item['description']
|
| 733 |
+
links = item['links']
|
| 734 |
+
|
| 735 |
+
if count > 0:
|
| 736 |
+
output += generate_output(
|
| 737 |
+
line=str(int(line)+1),
|
| 738 |
+
is_parent=True,
|
| 739 |
+
colorize=colorize
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
output += generate_output(
|
| 743 |
+
line=str(int(line)+1),
|
| 744 |
+
short=HR_RDAP_COMMON[key]['title']['_short'] if hr else (
|
| 745 |
+
'title'),
|
| 746 |
+
name=HR_RDAP_COMMON[key]['title']['_name'] if (
|
| 747 |
+
hr and show_name) else None,
|
| 748 |
+
value=title,
|
| 749 |
+
colorize=colorize
|
| 750 |
+
)
|
| 751 |
+
|
| 752 |
+
output += generate_output(
|
| 753 |
+
line=str(int(line)+1),
|
| 754 |
+
short=HR_RDAP_COMMON[key]['description'][
|
| 755 |
+
'_short'] if hr else 'description',
|
| 756 |
+
name=HR_RDAP_COMMON[key]['description'][
|
| 757 |
+
'_name'] if (hr and show_name) else None,
|
| 758 |
+
value=description.replace(
|
| 759 |
+
'\n',
|
| 760 |
+
'\n{0}'.format(generate_output(line='3'))
|
| 761 |
+
),
|
| 762 |
+
colorize=colorize
|
| 763 |
+
)
|
| 764 |
+
output += self.generate_output_list(
|
| 765 |
+
source=source,
|
| 766 |
+
key='links',
|
| 767 |
+
val=links,
|
| 768 |
+
line=str(int(line)+1),
|
| 769 |
+
hr=hr,
|
| 770 |
+
show_name=show_name,
|
| 771 |
+
colorize=colorize
|
| 772 |
+
)
|
| 773 |
+
|
| 774 |
+
count += 1
|
| 775 |
+
|
| 776 |
+
return output
|
| 777 |
+
|
| 778 |
+
def generate_output_network(self, json_data=None, hr=True, show_name=False,
|
| 779 |
+
colorize=True):
|
| 780 |
+
"""
|
| 781 |
+
The function for generating CLI output RDAP network results.
|
| 782 |
+
|
| 783 |
+
Args:
|
| 784 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 785 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 786 |
+
to True.
|
| 787 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 788 |
+
only show short). Defaults to False.
|
| 789 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 790 |
+
colors. Defaults to True.
|
| 791 |
+
|
| 792 |
+
Returns:
|
| 793 |
+
str: The generated output.
|
| 794 |
+
"""
|
| 795 |
+
|
| 796 |
+
if json_data is None:
|
| 797 |
+
json_data = {}
|
| 798 |
+
|
| 799 |
+
output = generate_output(
|
| 800 |
+
line='0',
|
| 801 |
+
short=HR_RDAP['network']['_short'] if hr else 'network',
|
| 802 |
+
name=HR_RDAP['network']['_name'] if (hr and show_name) else None,
|
| 803 |
+
is_parent=True,
|
| 804 |
+
colorize=colorize
|
| 805 |
+
)
|
| 806 |
+
|
| 807 |
+
for key, val in json_data['network'].items():
|
| 808 |
+
|
| 809 |
+
if key in ['links', 'status']:
|
| 810 |
+
|
| 811 |
+
output += self.generate_output_list(
|
| 812 |
+
source='network',
|
| 813 |
+
key=key,
|
| 814 |
+
val=val,
|
| 815 |
+
line='1',
|
| 816 |
+
hr=hr,
|
| 817 |
+
show_name=show_name,
|
| 818 |
+
colorize=colorize
|
| 819 |
+
)
|
| 820 |
+
|
| 821 |
+
elif key in ['notices', 'remarks']:
|
| 822 |
+
|
| 823 |
+
output += self.generate_output_notices(
|
| 824 |
+
source='network',
|
| 825 |
+
key=key,
|
| 826 |
+
val=val,
|
| 827 |
+
line='1',
|
| 828 |
+
hr=hr,
|
| 829 |
+
show_name=show_name,
|
| 830 |
+
colorize=colorize
|
| 831 |
+
)
|
| 832 |
+
|
| 833 |
+
elif key == 'events':
|
| 834 |
+
|
| 835 |
+
output += self.generate_output_events(
|
| 836 |
+
source='network',
|
| 837 |
+
key=key,
|
| 838 |
+
val=val,
|
| 839 |
+
line='1',
|
| 840 |
+
hr=hr,
|
| 841 |
+
show_name=show_name,
|
| 842 |
+
colorize=colorize
|
| 843 |
+
)
|
| 844 |
+
|
| 845 |
+
elif key not in ['raw']:
|
| 846 |
+
|
| 847 |
+
output += generate_output(
|
| 848 |
+
line='1',
|
| 849 |
+
short=HR_RDAP['network'][key]['_short'] if hr else key,
|
| 850 |
+
name=HR_RDAP['network'][key]['_name'] if (
|
| 851 |
+
hr and show_name) else None,
|
| 852 |
+
value=val,
|
| 853 |
+
colorize=colorize
|
| 854 |
+
)
|
| 855 |
+
|
| 856 |
+
return output
|
| 857 |
+
|
| 858 |
+
def generate_output_objects(self, json_data=None, hr=True, show_name=False,
|
| 859 |
+
colorize=True):
|
| 860 |
+
"""
|
| 861 |
+
The function for generating CLI output RDAP object results.
|
| 862 |
+
|
| 863 |
+
Args:
|
| 864 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 865 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 866 |
+
to True.
|
| 867 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 868 |
+
only show short). Defaults to False.
|
| 869 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 870 |
+
colors. Defaults to True.
|
| 871 |
+
|
| 872 |
+
Returns:
|
| 873 |
+
str: The generated output.
|
| 874 |
+
"""
|
| 875 |
+
|
| 876 |
+
if json_data is None:
|
| 877 |
+
json_data = {}
|
| 878 |
+
|
| 879 |
+
output = generate_output(
|
| 880 |
+
line='0',
|
| 881 |
+
short=HR_RDAP['objects']['_short'] if hr else 'objects',
|
| 882 |
+
name=HR_RDAP['objects']['_name'] if (hr and show_name) else None,
|
| 883 |
+
is_parent=True,
|
| 884 |
+
colorize=colorize
|
| 885 |
+
)
|
| 886 |
+
|
| 887 |
+
count = 0
|
| 888 |
+
for obj_name, obj in json_data['objects'].items():
|
| 889 |
+
if count > 0:
|
| 890 |
+
output += self.generate_output_newline(
|
| 891 |
+
line='1',
|
| 892 |
+
colorize=colorize
|
| 893 |
+
)
|
| 894 |
+
count += 1
|
| 895 |
+
|
| 896 |
+
output += generate_output(
|
| 897 |
+
line='1',
|
| 898 |
+
short=obj_name,
|
| 899 |
+
is_parent=True,
|
| 900 |
+
colorize=colorize
|
| 901 |
+
)
|
| 902 |
+
|
| 903 |
+
for key, val in obj.items():
|
| 904 |
+
|
| 905 |
+
if key in ['links', 'entities', 'roles', 'status']:
|
| 906 |
+
|
| 907 |
+
output += self.generate_output_list(
|
| 908 |
+
source='objects',
|
| 909 |
+
key=key,
|
| 910 |
+
val=val,
|
| 911 |
+
line='2',
|
| 912 |
+
hr=hr,
|
| 913 |
+
show_name=show_name,
|
| 914 |
+
colorize=colorize
|
| 915 |
+
)
|
| 916 |
+
|
| 917 |
+
elif key in ['notices', 'remarks']:
|
| 918 |
+
|
| 919 |
+
output += self.generate_output_notices(
|
| 920 |
+
source='objects',
|
| 921 |
+
key=key,
|
| 922 |
+
val=val,
|
| 923 |
+
line='2',
|
| 924 |
+
hr=hr,
|
| 925 |
+
show_name=show_name,
|
| 926 |
+
colorize=colorize
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
elif key == 'events':
|
| 930 |
+
|
| 931 |
+
output += self.generate_output_events(
|
| 932 |
+
source='objects',
|
| 933 |
+
key=key,
|
| 934 |
+
val=val,
|
| 935 |
+
line='2',
|
| 936 |
+
hr=hr,
|
| 937 |
+
show_name=show_name,
|
| 938 |
+
colorize=colorize
|
| 939 |
+
)
|
| 940 |
+
|
| 941 |
+
elif key == 'contact':
|
| 942 |
+
|
| 943 |
+
output += generate_output(
|
| 944 |
+
line='2',
|
| 945 |
+
short=HR_RDAP['objects']['contact'][
|
| 946 |
+
'_short'] if hr else 'contact',
|
| 947 |
+
name=HR_RDAP['objects']['contact']['_name'] if (
|
| 948 |
+
hr and show_name) else None,
|
| 949 |
+
is_parent=False if (val is None or
|
| 950 |
+
len(val) == 0) else True,
|
| 951 |
+
value='None' if (val is None or
|
| 952 |
+
len(val) == 0) else None,
|
| 953 |
+
colorize=colorize
|
| 954 |
+
)
|
| 955 |
+
|
| 956 |
+
if val is not None:
|
| 957 |
+
|
| 958 |
+
for k, v in val.items():
|
| 959 |
+
|
| 960 |
+
if k in ['phone', 'address', 'email']:
|
| 961 |
+
|
| 962 |
+
output += generate_output(
|
| 963 |
+
line='3',
|
| 964 |
+
short=HR_RDAP['objects']['contact'][k][
|
| 965 |
+
'_short'] if hr else k,
|
| 966 |
+
name=HR_RDAP['objects']['contact'][k][
|
| 967 |
+
'_name'] if (
|
| 968 |
+
hr and show_name) else None,
|
| 969 |
+
is_parent=False if (
|
| 970 |
+
val is None or
|
| 971 |
+
len(val) == 0
|
| 972 |
+
) else True,
|
| 973 |
+
value='None' if (val is None or
|
| 974 |
+
len(val) == 0) else None,
|
| 975 |
+
colorize=colorize
|
| 976 |
+
)
|
| 977 |
+
|
| 978 |
+
if v is not None:
|
| 979 |
+
for item in v:
|
| 980 |
+
i_type = ', '.join(item['type']) if (
|
| 981 |
+
isinstance(item['type'], list)
|
| 982 |
+
) else item['type']
|
| 983 |
+
|
| 984 |
+
i_type = i_type if (
|
| 985 |
+
i_type is not None and
|
| 986 |
+
len(i_type) > 0) else ''
|
| 987 |
+
|
| 988 |
+
i_value = item['value'].replace(
|
| 989 |
+
'\n',
|
| 990 |
+
'\n{0}'.format(
|
| 991 |
+
generate_output(
|
| 992 |
+
line='4',
|
| 993 |
+
is_parent=True,
|
| 994 |
+
colorize=colorize
|
| 995 |
+
).replace('\n', ''))
|
| 996 |
+
)
|
| 997 |
+
|
| 998 |
+
tmp_out = '{0}{1}{2}'.format(
|
| 999 |
+
i_type,
|
| 1000 |
+
': ' if i_type != '' else '',
|
| 1001 |
+
i_value
|
| 1002 |
+
)
|
| 1003 |
+
|
| 1004 |
+
output += generate_output(
|
| 1005 |
+
line='4',
|
| 1006 |
+
value=tmp_out,
|
| 1007 |
+
colorize=colorize
|
| 1008 |
+
)
|
| 1009 |
+
|
| 1010 |
+
else:
|
| 1011 |
+
|
| 1012 |
+
output += generate_output(
|
| 1013 |
+
line='3',
|
| 1014 |
+
short=HR_RDAP['objects']['contact'][k][
|
| 1015 |
+
'_short'] if hr else k,
|
| 1016 |
+
name=HR_RDAP['objects']['contact'][k][
|
| 1017 |
+
'_name'] if (
|
| 1018 |
+
hr and show_name) else None,
|
| 1019 |
+
value=v,
|
| 1020 |
+
colorize=colorize
|
| 1021 |
+
)
|
| 1022 |
+
|
| 1023 |
+
elif key not in ['raw']:
|
| 1024 |
+
|
| 1025 |
+
output += generate_output(
|
| 1026 |
+
line='2',
|
| 1027 |
+
short=HR_RDAP['objects'][key]['_short'] if hr else key,
|
| 1028 |
+
name=HR_RDAP['objects'][key]['_name'] if (
|
| 1029 |
+
hr and show_name) else None,
|
| 1030 |
+
value=val,
|
| 1031 |
+
colorize=colorize
|
| 1032 |
+
)
|
| 1033 |
+
|
| 1034 |
+
return output
|
| 1035 |
+
|
| 1036 |
+
def lookup_rdap(self, hr=True, show_name=False, colorize=True, **kwargs):
|
| 1037 |
+
"""
|
| 1038 |
+
The function for wrapping IPWhois.lookup_rdap() and generating
|
| 1039 |
+
formatted CLI output.
|
| 1040 |
+
|
| 1041 |
+
Args:
|
| 1042 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 1043 |
+
to True.
|
| 1044 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 1045 |
+
only show short). Defaults to False.
|
| 1046 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 1047 |
+
colors. Defaults to True.
|
| 1048 |
+
kwargs: Arguments to pass to IPWhois.lookup_rdap().
|
| 1049 |
+
|
| 1050 |
+
Returns:
|
| 1051 |
+
str: The generated output.
|
| 1052 |
+
"""
|
| 1053 |
+
|
| 1054 |
+
# Perform the RDAP lookup
|
| 1055 |
+
ret = self.obj.lookup_rdap(**kwargs)
|
| 1056 |
+
|
| 1057 |
+
if script_args.json:
|
| 1058 |
+
|
| 1059 |
+
output = json.dumps(ret)
|
| 1060 |
+
|
| 1061 |
+
else:
|
| 1062 |
+
|
| 1063 |
+
# Header
|
| 1064 |
+
output = self.generate_output_header(query_type='RDAP')
|
| 1065 |
+
|
| 1066 |
+
# ASN
|
| 1067 |
+
output += self.generate_output_asn(
|
| 1068 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1069 |
+
)
|
| 1070 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1071 |
+
|
| 1072 |
+
# Entities
|
| 1073 |
+
output += self.generate_output_entities(
|
| 1074 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1075 |
+
)
|
| 1076 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1077 |
+
|
| 1078 |
+
# Network
|
| 1079 |
+
output += self.generate_output_network(
|
| 1080 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1081 |
+
)
|
| 1082 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1083 |
+
|
| 1084 |
+
# Objects
|
| 1085 |
+
output += self.generate_output_objects(
|
| 1086 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1087 |
+
)
|
| 1088 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1089 |
+
|
| 1090 |
+
if 'nir' in ret:
|
| 1091 |
+
|
| 1092 |
+
# NIR
|
| 1093 |
+
output += self.generate_output_nir(
|
| 1094 |
+
json_data=ret, hr=hr, show_name=show_name,
|
| 1095 |
+
colorize=colorize
|
| 1096 |
+
)
|
| 1097 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1098 |
+
|
| 1099 |
+
return output
|
| 1100 |
+
|
| 1101 |
+
def generate_output_whois_nets(self, json_data=None, hr=True,
|
| 1102 |
+
show_name=False, colorize=True):
|
| 1103 |
+
"""
|
| 1104 |
+
The function for generating CLI output Legacy Whois networks results.
|
| 1105 |
+
|
| 1106 |
+
Args:
|
| 1107 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 1108 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 1109 |
+
to True.
|
| 1110 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 1111 |
+
only show short). Defaults to False.
|
| 1112 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 1113 |
+
colors. Defaults to True.
|
| 1114 |
+
|
| 1115 |
+
Returns:
|
| 1116 |
+
str: The generated output.
|
| 1117 |
+
"""
|
| 1118 |
+
|
| 1119 |
+
if json_data is None:
|
| 1120 |
+
json_data = {}
|
| 1121 |
+
|
| 1122 |
+
output = generate_output(
|
| 1123 |
+
line='0',
|
| 1124 |
+
short=HR_WHOIS['nets']['_short'] if hr else 'nets',
|
| 1125 |
+
name=HR_WHOIS['nets']['_name'] if (hr and show_name) else None,
|
| 1126 |
+
is_parent=True,
|
| 1127 |
+
colorize=colorize
|
| 1128 |
+
)
|
| 1129 |
+
|
| 1130 |
+
count = 0
|
| 1131 |
+
for net in json_data['nets']:
|
| 1132 |
+
if count > 0:
|
| 1133 |
+
output += self.generate_output_newline(
|
| 1134 |
+
line='1',
|
| 1135 |
+
colorize=colorize
|
| 1136 |
+
)
|
| 1137 |
+
count += 1
|
| 1138 |
+
|
| 1139 |
+
output += generate_output(
|
| 1140 |
+
line='1',
|
| 1141 |
+
short=net['handle'],
|
| 1142 |
+
is_parent=True,
|
| 1143 |
+
colorize=colorize
|
| 1144 |
+
)
|
| 1145 |
+
|
| 1146 |
+
for key, val in net.items():
|
| 1147 |
+
|
| 1148 |
+
if val and '\n' in val:
|
| 1149 |
+
|
| 1150 |
+
output += generate_output(
|
| 1151 |
+
line='2',
|
| 1152 |
+
short=HR_WHOIS['nets'][key]['_short'] if hr else key,
|
| 1153 |
+
name=HR_WHOIS['nets'][key]['_name'] if (
|
| 1154 |
+
hr and show_name) else None,
|
| 1155 |
+
is_parent=False if (val is None or
|
| 1156 |
+
len(val) == 0) else True,
|
| 1157 |
+
value='None' if (val is None or
|
| 1158 |
+
len(val) == 0) else None,
|
| 1159 |
+
colorize=colorize
|
| 1160 |
+
)
|
| 1161 |
+
|
| 1162 |
+
for v in val.split('\n'):
|
| 1163 |
+
output += generate_output(
|
| 1164 |
+
line='3',
|
| 1165 |
+
value=v,
|
| 1166 |
+
colorize=colorize
|
| 1167 |
+
)
|
| 1168 |
+
|
| 1169 |
+
else:
|
| 1170 |
+
|
| 1171 |
+
output += generate_output(
|
| 1172 |
+
line='2',
|
| 1173 |
+
short=HR_WHOIS['nets'][key]['_short'] if hr else key,
|
| 1174 |
+
name=HR_WHOIS['nets'][key]['_name'] if (
|
| 1175 |
+
hr and show_name) else None,
|
| 1176 |
+
value=val,
|
| 1177 |
+
colorize=colorize
|
| 1178 |
+
)
|
| 1179 |
+
|
| 1180 |
+
return output
|
| 1181 |
+
|
| 1182 |
+
def generate_output_whois_referral(self, json_data=None, hr=True,
|
| 1183 |
+
show_name=False, colorize=True):
|
| 1184 |
+
"""
|
| 1185 |
+
The function for generating CLI output Legacy Whois referral results.
|
| 1186 |
+
|
| 1187 |
+
Args:
|
| 1188 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 1189 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 1190 |
+
to True.
|
| 1191 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 1192 |
+
only show short). Defaults to False.
|
| 1193 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 1194 |
+
colors. Defaults to True.
|
| 1195 |
+
|
| 1196 |
+
Returns:
|
| 1197 |
+
str: The generated output.
|
| 1198 |
+
"""
|
| 1199 |
+
|
| 1200 |
+
if json_data is None:
|
| 1201 |
+
json_data = {}
|
| 1202 |
+
|
| 1203 |
+
output = generate_output(
|
| 1204 |
+
line='0',
|
| 1205 |
+
short=HR_WHOIS['referral']['_short'] if hr else 'referral',
|
| 1206 |
+
name=HR_WHOIS['referral']['_name'] if (hr and show_name) else None,
|
| 1207 |
+
is_parent=False if json_data['referral'] is None else True,
|
| 1208 |
+
value='None' if json_data['referral'] is None else None,
|
| 1209 |
+
colorize=colorize
|
| 1210 |
+
)
|
| 1211 |
+
|
| 1212 |
+
if json_data['referral']:
|
| 1213 |
+
|
| 1214 |
+
for key, val in json_data['referral'].items():
|
| 1215 |
+
|
| 1216 |
+
if val and '\n' in val:
|
| 1217 |
+
|
| 1218 |
+
output += generate_output(
|
| 1219 |
+
line='1',
|
| 1220 |
+
short=HR_WHOIS['nets'][key]['_short'] if hr else key,
|
| 1221 |
+
name=HR_WHOIS['nets'][key]['_name'] if (
|
| 1222 |
+
hr and show_name) else None,
|
| 1223 |
+
is_parent=False if (val is None or
|
| 1224 |
+
len(val) == 0) else True,
|
| 1225 |
+
value='None' if (val is None or
|
| 1226 |
+
len(val) == 0) else None,
|
| 1227 |
+
colorize=colorize
|
| 1228 |
+
)
|
| 1229 |
+
|
| 1230 |
+
for v in val.split('\n'):
|
| 1231 |
+
output += generate_output(
|
| 1232 |
+
line='2',
|
| 1233 |
+
value=v,
|
| 1234 |
+
colorize=colorize
|
| 1235 |
+
)
|
| 1236 |
+
|
| 1237 |
+
else:
|
| 1238 |
+
|
| 1239 |
+
output += generate_output(
|
| 1240 |
+
line='1',
|
| 1241 |
+
short=HR_WHOIS['nets'][key]['_short'] if hr else key,
|
| 1242 |
+
name=HR_WHOIS['nets'][key]['_name'] if (
|
| 1243 |
+
hr and show_name) else None,
|
| 1244 |
+
value=val,
|
| 1245 |
+
colorize=colorize
|
| 1246 |
+
)
|
| 1247 |
+
|
| 1248 |
+
return output
|
| 1249 |
+
|
| 1250 |
+
def generate_output_nir(self, json_data=None, hr=True, show_name=False,
|
| 1251 |
+
colorize=True):
|
| 1252 |
+
"""
|
| 1253 |
+
The function for generating CLI output NIR network results.
|
| 1254 |
+
|
| 1255 |
+
Args:
|
| 1256 |
+
json_data (:obj:`dict`): The data to process. Defaults to None.
|
| 1257 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 1258 |
+
to True.
|
| 1259 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 1260 |
+
only show short). Defaults to False.
|
| 1261 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 1262 |
+
colors. Defaults to True.
|
| 1263 |
+
|
| 1264 |
+
Returns:
|
| 1265 |
+
str: The generated output.
|
| 1266 |
+
"""
|
| 1267 |
+
|
| 1268 |
+
if json_data is None:
|
| 1269 |
+
json_data = {}
|
| 1270 |
+
|
| 1271 |
+
output = generate_output(
|
| 1272 |
+
line='0',
|
| 1273 |
+
short=HR_WHOIS_NIR['nets']['_short'] if hr else 'nir_nets',
|
| 1274 |
+
name=HR_WHOIS_NIR['nets']['_name'] if (hr and show_name) else None,
|
| 1275 |
+
is_parent=True,
|
| 1276 |
+
colorize=colorize
|
| 1277 |
+
)
|
| 1278 |
+
|
| 1279 |
+
count = 0
|
| 1280 |
+
if json_data['nir']:
|
| 1281 |
+
|
| 1282 |
+
for net in json_data['nir']['nets']:
|
| 1283 |
+
|
| 1284 |
+
if count > 0:
|
| 1285 |
+
|
| 1286 |
+
output += self.generate_output_newline(
|
| 1287 |
+
line='1',
|
| 1288 |
+
colorize=colorize
|
| 1289 |
+
)
|
| 1290 |
+
|
| 1291 |
+
count += 1
|
| 1292 |
+
|
| 1293 |
+
output += generate_output(
|
| 1294 |
+
line='1',
|
| 1295 |
+
short=net['handle'],
|
| 1296 |
+
is_parent=True,
|
| 1297 |
+
colorize=colorize
|
| 1298 |
+
)
|
| 1299 |
+
|
| 1300 |
+
for key, val in net.items():
|
| 1301 |
+
|
| 1302 |
+
if val and (isinstance(val, dict) or '\n' in val or
|
| 1303 |
+
key == 'nameservers'):
|
| 1304 |
+
|
| 1305 |
+
output += generate_output(
|
| 1306 |
+
line='2',
|
| 1307 |
+
short=(
|
| 1308 |
+
HR_WHOIS_NIR['nets'][key]['_short'] if (
|
| 1309 |
+
hr) else key
|
| 1310 |
+
),
|
| 1311 |
+
name=HR_WHOIS_NIR['nets'][key]['_name'] if (
|
| 1312 |
+
hr and show_name) else None,
|
| 1313 |
+
is_parent=False if (val is None or
|
| 1314 |
+
len(val) == 0) else True,
|
| 1315 |
+
value='None' if (val is None or
|
| 1316 |
+
len(val) == 0) else None,
|
| 1317 |
+
colorize=colorize
|
| 1318 |
+
)
|
| 1319 |
+
|
| 1320 |
+
if key == 'contacts':
|
| 1321 |
+
|
| 1322 |
+
for k, v in val.items():
|
| 1323 |
+
|
| 1324 |
+
if v:
|
| 1325 |
+
|
| 1326 |
+
output += generate_output(
|
| 1327 |
+
line='3',
|
| 1328 |
+
is_parent=False if (
|
| 1329 |
+
len(v) == 0) else True,
|
| 1330 |
+
name=k,
|
| 1331 |
+
colorize=colorize
|
| 1332 |
+
)
|
| 1333 |
+
|
| 1334 |
+
for contact_key, contact_val in v.items():
|
| 1335 |
+
|
| 1336 |
+
if v is not None:
|
| 1337 |
+
|
| 1338 |
+
tmp_out = '{0}{1}{2}'.format(
|
| 1339 |
+
contact_key,
|
| 1340 |
+
': ',
|
| 1341 |
+
contact_val
|
| 1342 |
+
)
|
| 1343 |
+
|
| 1344 |
+
output += generate_output(
|
| 1345 |
+
line='4',
|
| 1346 |
+
value=tmp_out,
|
| 1347 |
+
colorize=colorize
|
| 1348 |
+
)
|
| 1349 |
+
elif key == 'nameservers':
|
| 1350 |
+
|
| 1351 |
+
for v in val:
|
| 1352 |
+
output += generate_output(
|
| 1353 |
+
line='3',
|
| 1354 |
+
value=v,
|
| 1355 |
+
colorize=colorize
|
| 1356 |
+
)
|
| 1357 |
+
else:
|
| 1358 |
+
|
| 1359 |
+
for v in val.split('\n'):
|
| 1360 |
+
output += generate_output(
|
| 1361 |
+
line='3',
|
| 1362 |
+
value=v,
|
| 1363 |
+
colorize=colorize
|
| 1364 |
+
)
|
| 1365 |
+
|
| 1366 |
+
else:
|
| 1367 |
+
|
| 1368 |
+
output += generate_output(
|
| 1369 |
+
line='2',
|
| 1370 |
+
short=(
|
| 1371 |
+
HR_WHOIS_NIR['nets'][key]['_short'] if (
|
| 1372 |
+
hr) else key
|
| 1373 |
+
),
|
| 1374 |
+
name=HR_WHOIS_NIR['nets'][key]['_name'] if (
|
| 1375 |
+
hr and show_name) else None,
|
| 1376 |
+
value=val,
|
| 1377 |
+
colorize=colorize
|
| 1378 |
+
)
|
| 1379 |
+
|
| 1380 |
+
else:
|
| 1381 |
+
|
| 1382 |
+
output += 'None'
|
| 1383 |
+
|
| 1384 |
+
return output
|
| 1385 |
+
|
| 1386 |
+
def lookup_whois(self, hr=True, show_name=False, colorize=True, **kwargs):
|
| 1387 |
+
"""
|
| 1388 |
+
The function for wrapping IPWhois.lookup_whois() and generating
|
| 1389 |
+
formatted CLI output.
|
| 1390 |
+
|
| 1391 |
+
Args:
|
| 1392 |
+
hr (:obj:`bool`): Enable human readable key translations. Defaults
|
| 1393 |
+
to True.
|
| 1394 |
+
show_name (:obj:`bool`): Show human readable name (default is to
|
| 1395 |
+
only show short). Defaults to False.
|
| 1396 |
+
colorize (:obj:`bool`): Colorize the console output with ANSI
|
| 1397 |
+
colors. Defaults to True.
|
| 1398 |
+
kwargs: Arguments to pass to IPWhois.lookup_whois().
|
| 1399 |
+
|
| 1400 |
+
Returns:
|
| 1401 |
+
str: The generated output.
|
| 1402 |
+
"""
|
| 1403 |
+
|
| 1404 |
+
# Perform the RDAP lookup
|
| 1405 |
+
ret = self.obj.lookup_whois(**kwargs)
|
| 1406 |
+
|
| 1407 |
+
if script_args.json:
|
| 1408 |
+
|
| 1409 |
+
output = json.dumps(ret)
|
| 1410 |
+
|
| 1411 |
+
else:
|
| 1412 |
+
|
| 1413 |
+
# Header
|
| 1414 |
+
output = self.generate_output_header(query_type='Legacy Whois')
|
| 1415 |
+
|
| 1416 |
+
# ASN
|
| 1417 |
+
output += self.generate_output_asn(
|
| 1418 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1419 |
+
)
|
| 1420 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1421 |
+
|
| 1422 |
+
# Network
|
| 1423 |
+
output += self.generate_output_whois_nets(
|
| 1424 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1425 |
+
)
|
| 1426 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1427 |
+
|
| 1428 |
+
# Referral
|
| 1429 |
+
output += self.generate_output_whois_referral(
|
| 1430 |
+
json_data=ret, hr=hr, show_name=show_name, colorize=colorize
|
| 1431 |
+
)
|
| 1432 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1433 |
+
|
| 1434 |
+
if 'nir' in ret:
|
| 1435 |
+
|
| 1436 |
+
# NIR
|
| 1437 |
+
output += self.generate_output_nir(
|
| 1438 |
+
json_data=ret, hr=hr, show_name=show_name,
|
| 1439 |
+
colorize=colorize
|
| 1440 |
+
)
|
| 1441 |
+
output += self.generate_output_newline(colorize=colorize)
|
| 1442 |
+
|
| 1443 |
+
return output
|
| 1444 |
+
|
| 1445 |
+
if script_args.addr:
|
| 1446 |
+
|
| 1447 |
+
results = IPWhoisCLI(
|
| 1448 |
+
addr=script_args.addr[0],
|
| 1449 |
+
timeout=script_args.timeout,
|
| 1450 |
+
proxy_http=script_args.proxy_http if (
|
| 1451 |
+
script_args.proxy_http and len(script_args.proxy_http) > 0
|
| 1452 |
+
) else None,
|
| 1453 |
+
proxy_https=script_args.proxy_https if (
|
| 1454 |
+
script_args.proxy_https and len(script_args.proxy_https) > 0
|
| 1455 |
+
) else None,
|
| 1456 |
+
allow_permutations=(not script_args.disallow_permutations)
|
| 1457 |
+
)
|
| 1458 |
+
|
| 1459 |
+
if script_args.whois:
|
| 1460 |
+
|
| 1461 |
+
print(results.lookup_whois(
|
| 1462 |
+
hr=script_args.hr,
|
| 1463 |
+
show_name=script_args.show_name,
|
| 1464 |
+
colorize=script_args.colorize,
|
| 1465 |
+
inc_raw=script_args.inc_raw,
|
| 1466 |
+
retry_count=script_args.retry_count,
|
| 1467 |
+
get_referral=script_args.get_referral,
|
| 1468 |
+
extra_blacklist=script_args.extra_blacklist.split(',') if (
|
| 1469 |
+
script_args.extra_blacklist and
|
| 1470 |
+
len(script_args.extra_blacklist) > 0) else None,
|
| 1471 |
+
ignore_referral_errors=script_args.ignore_referral_errors,
|
| 1472 |
+
field_list=script_args.field_list.split(',') if (
|
| 1473 |
+
script_args.field_list and
|
| 1474 |
+
len(script_args.field_list) > 0) else None,
|
| 1475 |
+
asn_alts=script_args.asn_alts.split(',') if (
|
| 1476 |
+
script_args.asn_alts and not script_args.asn_methods and
|
| 1477 |
+
len(script_args.asn_alts) > 0) else None,
|
| 1478 |
+
extra_org_map=script_args.extra_org_map,
|
| 1479 |
+
inc_nir=(not script_args.exclude_nir),
|
| 1480 |
+
nir_field_list=script_args.nir_field_list.split(',') if (
|
| 1481 |
+
script_args.nir_field_list and
|
| 1482 |
+
len(script_args.nir_field_list) > 0) else None,
|
| 1483 |
+
asn_methods=script_args.asn_methods.split(',') if (
|
| 1484 |
+
script_args.asn_methods and
|
| 1485 |
+
len(script_args.asn_methods) > 0) else None,
|
| 1486 |
+
get_asn_description=(not script_args.skip_asn_description)
|
| 1487 |
+
))
|
| 1488 |
+
|
| 1489 |
+
else:
|
| 1490 |
+
|
| 1491 |
+
print(results.lookup_rdap(
|
| 1492 |
+
hr=script_args.hr,
|
| 1493 |
+
show_name=script_args.show_name,
|
| 1494 |
+
colorize=script_args.colorize,
|
| 1495 |
+
inc_raw=script_args.inc_raw,
|
| 1496 |
+
retry_count=script_args.retry_count,
|
| 1497 |
+
depth=script_args.depth,
|
| 1498 |
+
excluded_entities=script_args.excluded_entities.split(',') if (
|
| 1499 |
+
script_args.excluded_entities and
|
| 1500 |
+
len(script_args.excluded_entities) > 0) else None,
|
| 1501 |
+
bootstrap=script_args.bootstrap,
|
| 1502 |
+
rate_limit_timeout=script_args.rate_limit_timeout,
|
| 1503 |
+
asn_alts=script_args.asn_alts.split(',') if (
|
| 1504 |
+
script_args.asn_alts and not script_args.asn_methods and
|
| 1505 |
+
len(script_args.asn_alts) > 0) else None,
|
| 1506 |
+
extra_org_map=script_args.extra_org_map,
|
| 1507 |
+
inc_nir=(not script_args.exclude_nir),
|
| 1508 |
+
nir_field_list=script_args.nir_field_list.split(',') if (
|
| 1509 |
+
script_args.nir_field_list and
|
| 1510 |
+
len(script_args.nir_field_list) > 0) else None,
|
| 1511 |
+
asn_methods=script_args.asn_methods.split(',') if (
|
| 1512 |
+
script_args.asn_methods and
|
| 1513 |
+
len(script_args.asn_methods) > 0) else None,
|
| 1514 |
+
get_asn_description=(not script_args.skip_asn_description)
|
| 1515 |
+
))
|
spiderfoot/venv-spiderfoot/Scripts/ipwhois_utils_cli.py
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) 2013-2019 Philip Hane
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# Redistribution and use in source and binary forms, with or without
|
| 5 |
+
# modification, are permitted provided that the following conditions are met:
|
| 6 |
+
#
|
| 7 |
+
# 1. Redistributions of source code must retain the above copyright notice,
|
| 8 |
+
# this list of conditions and the following disclaimer.
|
| 9 |
+
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 10 |
+
# this list of conditions and the following disclaimer in the documentation
|
| 11 |
+
# and/or other materials provided with the distribution.
|
| 12 |
+
#
|
| 13 |
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 14 |
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 15 |
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 16 |
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 17 |
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
| 18 |
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
| 19 |
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
| 20 |
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
| 21 |
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
| 22 |
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
| 23 |
+
# POSSIBILITY OF SUCH DAMAGE.
|
| 24 |
+
|
| 25 |
+
# CLI python script interface for ipwhois.utils lookups.
|
| 26 |
+
|
| 27 |
+
import argparse
|
| 28 |
+
from collections import OrderedDict
|
| 29 |
+
import json
|
| 30 |
+
from ipwhois.utils import (ipv4_lstrip_zeros, calculate_cidr, get_countries,
|
| 31 |
+
ipv4_is_defined, ipv6_is_defined, unique_everseen,
|
| 32 |
+
unique_addresses)
|
| 33 |
+
|
| 34 |
+
# CLI ANSI rendering
|
| 35 |
+
ANSI = {
|
| 36 |
+
'end': '\033[0m',
|
| 37 |
+
'b': '\033[1m',
|
| 38 |
+
'ul': '\033[4m',
|
| 39 |
+
'red': '\033[31m',
|
| 40 |
+
'green': '\033[32m',
|
| 41 |
+
'yellow': '\033[33m',
|
| 42 |
+
'cyan': '\033[36m'
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
# Setup the arg parser.
|
| 46 |
+
parser = argparse.ArgumentParser(
|
| 47 |
+
description='ipwhois utilities CLI interface'
|
| 48 |
+
)
|
| 49 |
+
parser.add_argument(
|
| 50 |
+
'--ipv4_lstrip_zeros',
|
| 51 |
+
type=str,
|
| 52 |
+
nargs=1,
|
| 53 |
+
metavar='"IP ADDRESS"',
|
| 54 |
+
help='Strip leading zeros in each octet of an IPv4 address.'
|
| 55 |
+
)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
'--calculate_cidr',
|
| 58 |
+
type=str,
|
| 59 |
+
nargs=2,
|
| 60 |
+
metavar='"IP ADDRESS"',
|
| 61 |
+
help='Calculate a CIDR range(s) from a start and end IP address.'
|
| 62 |
+
)
|
| 63 |
+
parser.add_argument(
|
| 64 |
+
'--get_countries',
|
| 65 |
+
action='store_true',
|
| 66 |
+
help='Output a dictionary containing ISO_3166-1 country codes to names.'
|
| 67 |
+
)
|
| 68 |
+
parser.add_argument(
|
| 69 |
+
'--get_country',
|
| 70 |
+
type=str,
|
| 71 |
+
nargs=1,
|
| 72 |
+
metavar='"COUNTRY CODE"',
|
| 73 |
+
help='Output the ISO_3166-1 name for a country code.'
|
| 74 |
+
)
|
| 75 |
+
parser.add_argument(
|
| 76 |
+
'--ipv4_is_defined',
|
| 77 |
+
type=str,
|
| 78 |
+
nargs=1,
|
| 79 |
+
metavar='"IP ADDRESS"',
|
| 80 |
+
help='Check if an IPv4 address is defined (in a reserved address range).'
|
| 81 |
+
)
|
| 82 |
+
parser.add_argument(
|
| 83 |
+
'--ipv6_is_defined',
|
| 84 |
+
type=str,
|
| 85 |
+
nargs=1,
|
| 86 |
+
metavar='"IP ADDRESS"',
|
| 87 |
+
help='Check if an IPv6 address is defined (in a reserved address range).'
|
| 88 |
+
)
|
| 89 |
+
parser.add_argument(
|
| 90 |
+
'--unique_everseen',
|
| 91 |
+
type=json.loads,
|
| 92 |
+
nargs=1,
|
| 93 |
+
metavar='"ITERABLE"',
|
| 94 |
+
help='List unique elements from input iterable, preserving the order.'
|
| 95 |
+
)
|
| 96 |
+
parser.add_argument(
|
| 97 |
+
'--unique_addresses',
|
| 98 |
+
type=str,
|
| 99 |
+
nargs=1,
|
| 100 |
+
metavar='"FILE PATH"',
|
| 101 |
+
help='Search an input file, extracting, counting, and summarizing '
|
| 102 |
+
'IPv4/IPv6 addresses/networks.'
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
# Output options
|
| 106 |
+
group = parser.add_argument_group('Output options')
|
| 107 |
+
group.add_argument(
|
| 108 |
+
'--colorize',
|
| 109 |
+
action='store_true',
|
| 110 |
+
help='If set, colorizes the output using ANSI. Should work in most '
|
| 111 |
+
'platform consoles.'
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Get the args
|
| 115 |
+
script_args = parser.parse_args()
|
| 116 |
+
|
| 117 |
+
if script_args.ipv4_lstrip_zeros:
|
| 118 |
+
|
| 119 |
+
print(ipv4_lstrip_zeros(address=script_args.ipv4_lstrip_zeros[0]))
|
| 120 |
+
|
| 121 |
+
elif script_args.calculate_cidr:
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
|
| 125 |
+
result = calculate_cidr(
|
| 126 |
+
start_address=script_args.calculate_cidr[0],
|
| 127 |
+
end_address=script_args.calculate_cidr[1]
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
print('{0}Found {1} CIDR blocks for ({2}, {3}){4}:\n{5}'.format(
|
| 131 |
+
ANSI['green'] if script_args.colorize else '',
|
| 132 |
+
len(result),
|
| 133 |
+
script_args.calculate_cidr[0],
|
| 134 |
+
script_args.calculate_cidr[1],
|
| 135 |
+
ANSI['end'] if script_args.colorize else '',
|
| 136 |
+
'\n'.join(result)
|
| 137 |
+
))
|
| 138 |
+
|
| 139 |
+
except Exception as e:
|
| 140 |
+
|
| 141 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 142 |
+
|
| 143 |
+
elif script_args.get_countries:
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
|
| 147 |
+
result = get_countries()
|
| 148 |
+
|
| 149 |
+
print('{0}Found {1} countries{2}:\n{3}'.format(
|
| 150 |
+
ANSI['green'] if script_args.colorize else '',
|
| 151 |
+
len(result),
|
| 152 |
+
ANSI['end'] if script_args.colorize else '',
|
| 153 |
+
'\n'.join(['{0}: {1}'.format(k, v) for k, v in (
|
| 154 |
+
OrderedDict(sorted(result.items())).iteritems())])
|
| 155 |
+
))
|
| 156 |
+
|
| 157 |
+
except Exception as e:
|
| 158 |
+
|
| 159 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 160 |
+
|
| 161 |
+
elif script_args.get_country:
|
| 162 |
+
|
| 163 |
+
try:
|
| 164 |
+
|
| 165 |
+
countries = get_countries()
|
| 166 |
+
result = countries[script_args.get_country[0].upper()]
|
| 167 |
+
|
| 168 |
+
print('{0}Match found for country code ({1}){2}:\n{3}'.format(
|
| 169 |
+
ANSI['green'] if script_args.colorize else '',
|
| 170 |
+
script_args.get_country[0],
|
| 171 |
+
ANSI['end'] if script_args.colorize else '',
|
| 172 |
+
result
|
| 173 |
+
))
|
| 174 |
+
|
| 175 |
+
except Exception as e:
|
| 176 |
+
|
| 177 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 178 |
+
|
| 179 |
+
elif script_args.ipv4_is_defined:
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
|
| 183 |
+
result = ipv4_is_defined(address=script_args.ipv4_is_defined[0])
|
| 184 |
+
|
| 185 |
+
if result[0]:
|
| 186 |
+
print('{0}{1} is defined{2}:\n{3}'.format(
|
| 187 |
+
ANSI['green'] if script_args.colorize else '',
|
| 188 |
+
script_args.ipv4_is_defined[0],
|
| 189 |
+
ANSI['end'] if script_args.colorize else '',
|
| 190 |
+
'Name: {0}\nRFC: {1}'.format(result[1], result[2])
|
| 191 |
+
))
|
| 192 |
+
else:
|
| 193 |
+
print('{0}{1} is not defined{2}'.format(
|
| 194 |
+
ANSI['yellow'] if script_args.colorize else '',
|
| 195 |
+
script_args.ipv4_is_defined[0],
|
| 196 |
+
ANSI['end'] if script_args.colorize else ''
|
| 197 |
+
))
|
| 198 |
+
|
| 199 |
+
except Exception as e:
|
| 200 |
+
|
| 201 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 202 |
+
|
| 203 |
+
elif script_args.ipv6_is_defined:
|
| 204 |
+
|
| 205 |
+
try:
|
| 206 |
+
|
| 207 |
+
result = ipv6_is_defined(address=script_args.ipv6_is_defined[0])
|
| 208 |
+
|
| 209 |
+
if result[0]:
|
| 210 |
+
print('{0}{1} is defined{2}:\n{3}'.format(
|
| 211 |
+
ANSI['green'] if script_args.colorize else '',
|
| 212 |
+
script_args.ipv6_is_defined[0],
|
| 213 |
+
ANSI['end'] if script_args.colorize else '',
|
| 214 |
+
'Name: {0}\nRFC: {1}'.format(result[1], result[2])
|
| 215 |
+
))
|
| 216 |
+
else:
|
| 217 |
+
print('{0}{1} is not defined{2}'.format(
|
| 218 |
+
ANSI['yellow'] if script_args.colorize else '',
|
| 219 |
+
script_args.ipv6_is_defined[0],
|
| 220 |
+
ANSI['end'] if script_args.colorize else ''
|
| 221 |
+
))
|
| 222 |
+
|
| 223 |
+
except Exception as e:
|
| 224 |
+
|
| 225 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 226 |
+
|
| 227 |
+
elif script_args.unique_everseen:
|
| 228 |
+
|
| 229 |
+
try:
|
| 230 |
+
|
| 231 |
+
result = list(unique_everseen(iterable=script_args.unique_everseen[0]))
|
| 232 |
+
|
| 233 |
+
print('{0}Unique everseen{1}:\n{2}'.format(
|
| 234 |
+
ANSI['green'] if script_args.colorize else '',
|
| 235 |
+
ANSI['end'] if script_args.colorize else '',
|
| 236 |
+
result
|
| 237 |
+
))
|
| 238 |
+
|
| 239 |
+
except Exception as e:
|
| 240 |
+
|
| 241 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
| 242 |
+
|
| 243 |
+
elif script_args.unique_addresses:
|
| 244 |
+
|
| 245 |
+
try:
|
| 246 |
+
|
| 247 |
+
result = unique_addresses(file_path=script_args.unique_addresses[0])
|
| 248 |
+
|
| 249 |
+
tmp = []
|
| 250 |
+
for k, v in sorted(result.items(), key=lambda kv: int(kv[1]['count']),
|
| 251 |
+
reverse=True):
|
| 252 |
+
tmp.append('{0}{1}{2}: Count: {3}, Ports: {4}'.format(
|
| 253 |
+
ANSI['b'] if script_args.colorize else '',
|
| 254 |
+
k,
|
| 255 |
+
ANSI['end'] if script_args.colorize else '',
|
| 256 |
+
v['count'],
|
| 257 |
+
json.dumps(v['ports'])
|
| 258 |
+
))
|
| 259 |
+
|
| 260 |
+
print('{0}Found {1} unique addresses{2}:\n{3}'.format(
|
| 261 |
+
ANSI['green'] if script_args.colorize else '',
|
| 262 |
+
len(result),
|
| 263 |
+
ANSI['end'] if script_args.colorize else '',
|
| 264 |
+
'\n'.join(tmp)
|
| 265 |
+
))
|
| 266 |
+
|
| 267 |
+
except Exception as e:
|
| 268 |
+
|
| 269 |
+
print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))
|
spiderfoot/venv-spiderfoot/Scripts/vba_extract.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!c:\Ba7ath_project\dashboard_osint\spiderfoot\venv-spiderfoot\Scripts\python.exe
|
| 2 |
+
|
| 3 |
+
##############################################################################
|
| 4 |
+
#
|
| 5 |
+
# vba_extract - A simple utility to extract a vbaProject.bin binary from an
|
| 6 |
+
# Excel 2007+ xlsm file for insertion into an XlsxWriter file.
|
| 7 |
+
#
|
| 8 |
+
# SPDX-License-Identifier: BSD-2-Clause
|
| 9 |
+
#
|
| 10 |
+
# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org
|
| 11 |
+
#
|
| 12 |
+
|
| 13 |
+
import sys
|
| 14 |
+
from zipfile import BadZipFile, ZipFile
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def extract_file(xlsm_zip, filename):
|
| 18 |
+
# Extract a single file from an Excel xlsm macro file.
|
| 19 |
+
data = xlsm_zip.read("xl/" + filename)
|
| 20 |
+
|
| 21 |
+
# Write the data to a local file.
|
| 22 |
+
file = open(filename, "wb")
|
| 23 |
+
file.write(data)
|
| 24 |
+
file.close()
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
# The VBA project file and project signature file we want to extract.
|
| 28 |
+
vba_filename = "vbaProject.bin"
|
| 29 |
+
vba_signature_filename = "vbaProjectSignature.bin"
|
| 30 |
+
|
| 31 |
+
# Get the xlsm file name from the commandline.
|
| 32 |
+
if len(sys.argv) > 1:
|
| 33 |
+
xlsm_file = sys.argv[1]
|
| 34 |
+
else:
|
| 35 |
+
print(
|
| 36 |
+
"\nUtility to extract a vbaProject.bin binary from an Excel 2007+ "
|
| 37 |
+
"xlsm macro file for insertion into an XlsxWriter file.\n"
|
| 38 |
+
"If the macros are digitally signed, extracts also a vbaProjectSignature.bin "
|
| 39 |
+
"file.\n"
|
| 40 |
+
"\n"
|
| 41 |
+
"See: https://xlsxwriter.readthedocs.io/working_with_macros.html\n"
|
| 42 |
+
"\n"
|
| 43 |
+
"Usage: vba_extract file.xlsm\n"
|
| 44 |
+
)
|
| 45 |
+
sys.exit()
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
# Open the Excel xlsm file as a zip file.
|
| 49 |
+
xlsm_zip = ZipFile(xlsm_file, "r")
|
| 50 |
+
|
| 51 |
+
# Read the xl/vbaProject.bin file.
|
| 52 |
+
extract_file(xlsm_zip, vba_filename)
|
| 53 |
+
print(f"Extracted: {vba_filename}")
|
| 54 |
+
|
| 55 |
+
if "xl/" + vba_signature_filename in xlsm_zip.namelist():
|
| 56 |
+
extract_file(xlsm_zip, vba_signature_filename)
|
| 57 |
+
print(f"Extracted: {vba_signature_filename}")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
except IOError as e:
|
| 61 |
+
print(f"File error: {str(e)}")
|
| 62 |
+
sys.exit()
|
| 63 |
+
|
| 64 |
+
except KeyError as e:
|
| 65 |
+
# Usually when there isn't a xl/vbaProject.bin member in the file.
|
| 66 |
+
print(f"File error: {str(e)}")
|
| 67 |
+
print(f"File may not be an Excel xlsm macro file: '{xlsm_file}'")
|
| 68 |
+
sys.exit()
|
| 69 |
+
|
| 70 |
+
except BadZipFile as e:
|
| 71 |
+
# Usually if the file is an xls file and not an xlsm file.
|
| 72 |
+
print(f"File error: {str(e)}: '{xlsm_file}'")
|
| 73 |
+
print("File may not be an Excel xlsm macro file.")
|
| 74 |
+
sys.exit()
|
| 75 |
+
|
| 76 |
+
except Exception as e:
|
| 77 |
+
# Catch any other exceptions.
|
| 78 |
+
print(f"File error: {str(e)}")
|
| 79 |
+
sys.exit()
|
spiderfoot/venv-spiderfoot/pyvenv.cfg
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
home = C:\Users\user\AppData\Local\Programs\Python\Python311
|
| 2 |
+
include-system-site-packages = false
|
| 3 |
+
version = 3.11.0
|
| 4 |
+
executable = C:\Users\user\AppData\Local\Programs\Python\Python311\python.exe
|
| 5 |
+
command = C:\Users\user\AppData\Local\Programs\Python\Python311\python.exe -m venv c:\Ba7ath_project\dashboard_osint\spiderfoot\venv-spiderfoot
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/LICENSE.txt
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
NetworkX is distributed with the 3-clause BSD license.
|
| 2 |
+
|
| 3 |
+
::
|
| 4 |
+
|
| 5 |
+
Copyright (C) 2004-2021, NetworkX Developers
|
| 6 |
+
Aric Hagberg <hagberg@lanl.gov>
|
| 7 |
+
Dan Schult <dschult@colgate.edu>
|
| 8 |
+
Pieter Swart <swart@lanl.gov>
|
| 9 |
+
All rights reserved.
|
| 10 |
+
|
| 11 |
+
Redistribution and use in source and binary forms, with or without
|
| 12 |
+
modification, are permitted provided that the following conditions are
|
| 13 |
+
met:
|
| 14 |
+
|
| 15 |
+
* Redistributions of source code must retain the above copyright
|
| 16 |
+
notice, this list of conditions and the following disclaimer.
|
| 17 |
+
|
| 18 |
+
* Redistributions in binary form must reproduce the above
|
| 19 |
+
copyright notice, this list of conditions and the following
|
| 20 |
+
disclaimer in the documentation and/or other materials provided
|
| 21 |
+
with the distribution.
|
| 22 |
+
|
| 23 |
+
* Neither the name of the NetworkX Developers nor the names of its
|
| 24 |
+
contributors may be used to endorse or promote products derived
|
| 25 |
+
from this software without specific prior written permission.
|
| 26 |
+
|
| 27 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 28 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 29 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 30 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 31 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 32 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 33 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 34 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 35 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 36 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 37 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
3D Drawing
|
| 2 |
+
----------
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/mayavi2_spring.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=======
|
| 3 |
+
Mayavi2
|
| 4 |
+
=======
|
| 5 |
+
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import networkx as nx
|
| 9 |
+
import numpy as np
|
| 10 |
+
from mayavi import mlab
|
| 11 |
+
|
| 12 |
+
# some graphs to try
|
| 13 |
+
# H=nx.krackhardt_kite_graph()
|
| 14 |
+
# H=nx.Graph();H.add_edge('a','b');H.add_edge('a','c');H.add_edge('a','d')
|
| 15 |
+
# H=nx.grid_2d_graph(4,5)
|
| 16 |
+
H = nx.cycle_graph(20)
|
| 17 |
+
|
| 18 |
+
# reorder nodes from 0,len(G)-1
|
| 19 |
+
G = nx.convert_node_labels_to_integers(H)
|
| 20 |
+
# 3d spring layout
|
| 21 |
+
pos = nx.spring_layout(G, dim=3, seed=1001)
|
| 22 |
+
# numpy array of x,y,z positions in sorted node order
|
| 23 |
+
xyz = np.array([pos[v] for v in sorted(G)])
|
| 24 |
+
# scalar colors
|
| 25 |
+
scalars = np.array(list(G.nodes())) + 5
|
| 26 |
+
|
| 27 |
+
mlab.figure()
|
| 28 |
+
|
| 29 |
+
pts = mlab.points3d(
|
| 30 |
+
xyz[:, 0],
|
| 31 |
+
xyz[:, 1],
|
| 32 |
+
xyz[:, 2],
|
| 33 |
+
scalars,
|
| 34 |
+
scale_factor=0.1,
|
| 35 |
+
scale_mode="none",
|
| 36 |
+
colormap="Blues",
|
| 37 |
+
resolution=20,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
pts.mlab_source.dataset.lines = np.array(list(G.edges()))
|
| 41 |
+
tube = mlab.pipeline.tube(pts, tube_radius=0.01)
|
| 42 |
+
mlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8))
|
| 43 |
+
mlab.orientation_axes()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/3d_drawing/plot_basic.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
================
|
| 3 |
+
Basic matplotlib
|
| 4 |
+
================
|
| 5 |
+
|
| 6 |
+
A basic example of 3D Graph visualization using `mpl_toolkits.mplot_3d`.
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import networkx as nx
|
| 11 |
+
import numpy as np
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
from mpl_toolkits.mplot3d import Axes3D
|
| 14 |
+
|
| 15 |
+
# The graph to visualize
|
| 16 |
+
G = nx.cycle_graph(20)
|
| 17 |
+
|
| 18 |
+
# 3d spring layout
|
| 19 |
+
pos = nx.spring_layout(G, dim=3, seed=779)
|
| 20 |
+
# Extract node and edge positions from the layout
|
| 21 |
+
node_xyz = np.array([pos[v] for v in sorted(G)])
|
| 22 |
+
edge_xyz = np.array([(pos[u], pos[v]) for u, v in G.edges()])
|
| 23 |
+
|
| 24 |
+
# Create the 3D figure
|
| 25 |
+
fig = plt.figure()
|
| 26 |
+
ax = fig.add_subplot(111, projection="3d")
|
| 27 |
+
|
| 28 |
+
# Plot the nodes - alpha is scaled by "depth" automatically
|
| 29 |
+
ax.scatter(*node_xyz.T, s=100, ec="w")
|
| 30 |
+
|
| 31 |
+
# Plot the edges
|
| 32 |
+
for vizedge in edge_xyz:
|
| 33 |
+
ax.plot(*vizedge.T, color="tab:gray")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _format_axes(ax):
|
| 37 |
+
"""Visualization options for the 3D axes."""
|
| 38 |
+
# Turn gridlines off
|
| 39 |
+
ax.grid(False)
|
| 40 |
+
# Suppress tick labels
|
| 41 |
+
for dim in (ax.xaxis, ax.yaxis, ax.zaxis):
|
| 42 |
+
dim.set_ticks([])
|
| 43 |
+
# Set axes labels
|
| 44 |
+
ax.set_xlabel("x")
|
| 45 |
+
ax.set_ylabel("y")
|
| 46 |
+
ax.set_zlabel("z")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
_format_axes(ax)
|
| 50 |
+
fig.tight_layout()
|
| 51 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/README.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.. _examples_gallery:
|
| 2 |
+
|
| 3 |
+
Gallery
|
| 4 |
+
=======
|
| 5 |
+
|
| 6 |
+
General-purpose and introductory examples for NetworkX.
|
| 7 |
+
The `tutorial <../tutorial.html>`_ introduces conventions and basic graph
|
| 8 |
+
manipulations.
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Algorithms
|
| 2 |
+
----------
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/WormNet.v3.benchmark.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/hartford_drug.edgelist
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
14 24
|
| 26 |
+
14 52
|
| 27 |
+
16 10
|
| 28 |
+
16 19
|
| 29 |
+
17 64
|
| 30 |
+
17 78
|
| 31 |
+
18 55
|
| 32 |
+
18 103
|
| 33 |
+
18 163
|
| 34 |
+
19 18
|
| 35 |
+
20 64
|
| 36 |
+
20 180
|
| 37 |
+
21 16
|
| 38 |
+
21 22
|
| 39 |
+
22 21
|
| 40 |
+
22 64
|
| 41 |
+
22 106
|
| 42 |
+
23 20
|
| 43 |
+
23 22
|
| 44 |
+
23 64
|
| 45 |
+
24 14
|
| 46 |
+
24 31
|
| 47 |
+
24 122
|
| 48 |
+
27 115
|
| 49 |
+
28 29
|
| 50 |
+
29 28
|
| 51 |
+
30 19
|
| 52 |
+
31 24
|
| 53 |
+
31 32
|
| 54 |
+
31 122
|
| 55 |
+
31 147
|
| 56 |
+
31 233
|
| 57 |
+
32 31
|
| 58 |
+
32 86
|
| 59 |
+
34 35
|
| 60 |
+
34 37
|
| 61 |
+
35 34
|
| 62 |
+
35 43
|
| 63 |
+
36 132
|
| 64 |
+
36 187
|
| 65 |
+
37 38
|
| 66 |
+
37 90
|
| 67 |
+
37 282
|
| 68 |
+
38 42
|
| 69 |
+
38 43
|
| 70 |
+
38 210
|
| 71 |
+
40 20
|
| 72 |
+
42 15
|
| 73 |
+
42 38
|
| 74 |
+
43 34
|
| 75 |
+
43 35
|
| 76 |
+
43 38
|
| 77 |
+
45 107
|
| 78 |
+
46 61
|
| 79 |
+
46 72
|
| 80 |
+
48 23
|
| 81 |
+
49 30
|
| 82 |
+
49 64
|
| 83 |
+
49 108
|
| 84 |
+
49 115
|
| 85 |
+
49 243
|
| 86 |
+
50 30
|
| 87 |
+
50 47
|
| 88 |
+
50 55
|
| 89 |
+
50 125
|
| 90 |
+
50 163
|
| 91 |
+
52 218
|
| 92 |
+
52 224
|
| 93 |
+
54 111
|
| 94 |
+
54 210
|
| 95 |
+
55 65
|
| 96 |
+
55 67
|
| 97 |
+
55 105
|
| 98 |
+
55 108
|
| 99 |
+
55 222
|
| 100 |
+
56 18
|
| 101 |
+
56 64
|
| 102 |
+
57 65
|
| 103 |
+
57 125
|
| 104 |
+
58 20
|
| 105 |
+
58 30
|
| 106 |
+
58 50
|
| 107 |
+
58 103
|
| 108 |
+
58 180
|
| 109 |
+
59 164
|
| 110 |
+
63 125
|
| 111 |
+
64 8
|
| 112 |
+
64 50
|
| 113 |
+
64 70
|
| 114 |
+
64 256
|
| 115 |
+
66 20
|
| 116 |
+
66 84
|
| 117 |
+
66 106
|
| 118 |
+
66 125
|
| 119 |
+
67 22
|
| 120 |
+
67 50
|
| 121 |
+
67 113
|
| 122 |
+
68 50
|
| 123 |
+
70 50
|
| 124 |
+
70 64
|
| 125 |
+
71 72
|
| 126 |
+
74 29
|
| 127 |
+
74 75
|
| 128 |
+
74 215
|
| 129 |
+
75 74
|
| 130 |
+
75 215
|
| 131 |
+
76 58
|
| 132 |
+
76 104
|
| 133 |
+
77 103
|
| 134 |
+
78 64
|
| 135 |
+
78 68
|
| 136 |
+
80 207
|
| 137 |
+
80 210
|
| 138 |
+
82 8
|
| 139 |
+
82 77
|
| 140 |
+
82 83
|
| 141 |
+
82 97
|
| 142 |
+
82 163
|
| 143 |
+
83 82
|
| 144 |
+
83 226
|
| 145 |
+
83 243
|
| 146 |
+
84 29
|
| 147 |
+
84 154
|
| 148 |
+
87 101
|
| 149 |
+
87 189
|
| 150 |
+
89 90
|
| 151 |
+
90 89
|
| 152 |
+
90 94
|
| 153 |
+
91 86
|
| 154 |
+
92 19
|
| 155 |
+
92 30
|
| 156 |
+
92 106
|
| 157 |
+
94 72
|
| 158 |
+
94 89
|
| 159 |
+
94 90
|
| 160 |
+
95 30
|
| 161 |
+
96 75
|
| 162 |
+
96 256
|
| 163 |
+
97 80
|
| 164 |
+
97 128
|
| 165 |
+
98 86
|
| 166 |
+
100 86
|
| 167 |
+
101 87
|
| 168 |
+
103 77
|
| 169 |
+
103 104
|
| 170 |
+
104 58
|
| 171 |
+
104 77
|
| 172 |
+
104 103
|
| 173 |
+
106 22
|
| 174 |
+
107 38
|
| 175 |
+
107 114
|
| 176 |
+
107 122
|
| 177 |
+
108 49
|
| 178 |
+
108 55
|
| 179 |
+
111 121
|
| 180 |
+
111 128
|
| 181 |
+
111 210
|
| 182 |
+
113 253
|
| 183 |
+
114 107
|
| 184 |
+
116 30
|
| 185 |
+
116 140
|
| 186 |
+
118 129
|
| 187 |
+
118 138
|
| 188 |
+
120 88
|
| 189 |
+
121 128
|
| 190 |
+
122 31
|
| 191 |
+
123 32
|
| 192 |
+
124 244
|
| 193 |
+
125 132
|
| 194 |
+
126 163
|
| 195 |
+
126 180
|
| 196 |
+
128 38
|
| 197 |
+
128 111
|
| 198 |
+
129 118
|
| 199 |
+
132 29
|
| 200 |
+
132 30
|
| 201 |
+
133 30
|
| 202 |
+
134 135
|
| 203 |
+
134 150
|
| 204 |
+
135 134
|
| 205 |
+
137 144
|
| 206 |
+
138 118
|
| 207 |
+
138 129
|
| 208 |
+
139 142
|
| 209 |
+
141 157
|
| 210 |
+
141 163
|
| 211 |
+
142 139
|
| 212 |
+
143 2
|
| 213 |
+
144 137
|
| 214 |
+
145 151
|
| 215 |
+
146 137
|
| 216 |
+
146 165
|
| 217 |
+
146 169
|
| 218 |
+
146 171
|
| 219 |
+
147 31
|
| 220 |
+
147 128
|
| 221 |
+
148 146
|
| 222 |
+
148 169
|
| 223 |
+
148 171
|
| 224 |
+
148 282
|
| 225 |
+
149 128
|
| 226 |
+
149 148
|
| 227 |
+
149 172
|
| 228 |
+
150 86
|
| 229 |
+
151 145
|
| 230 |
+
152 4
|
| 231 |
+
153 134
|
| 232 |
+
154 155
|
| 233 |
+
156 161
|
| 234 |
+
157 141
|
| 235 |
+
161 156
|
| 236 |
+
165 144
|
| 237 |
+
165 148
|
| 238 |
+
167 149
|
| 239 |
+
169 15
|
| 240 |
+
169 148
|
| 241 |
+
169 171
|
| 242 |
+
170 115
|
| 243 |
+
170 173
|
| 244 |
+
170 183
|
| 245 |
+
170 202
|
| 246 |
+
171 72
|
| 247 |
+
171 148
|
| 248 |
+
171 169
|
| 249 |
+
173 170
|
| 250 |
+
175 100
|
| 251 |
+
176 10
|
| 252 |
+
178 181
|
| 253 |
+
181 178
|
| 254 |
+
182 38
|
| 255 |
+
182 171
|
| 256 |
+
183 96
|
| 257 |
+
185 50
|
| 258 |
+
186 127
|
| 259 |
+
187 50
|
| 260 |
+
187 65
|
| 261 |
+
188 30
|
| 262 |
+
188 50
|
| 263 |
+
189 87
|
| 264 |
+
189 89
|
| 265 |
+
190 35
|
| 266 |
+
190 38
|
| 267 |
+
190 122
|
| 268 |
+
190 182
|
| 269 |
+
191 54
|
| 270 |
+
191 118
|
| 271 |
+
191 129
|
| 272 |
+
191 172
|
| 273 |
+
192 149
|
| 274 |
+
192 167
|
| 275 |
+
195 75
|
| 276 |
+
197 50
|
| 277 |
+
197 188
|
| 278 |
+
198 218
|
| 279 |
+
198 221
|
| 280 |
+
198 222
|
| 281 |
+
200 65
|
| 282 |
+
200 220
|
| 283 |
+
201 113
|
| 284 |
+
202 156
|
| 285 |
+
203 232
|
| 286 |
+
204 194
|
| 287 |
+
207 38
|
| 288 |
+
207 122
|
| 289 |
+
207 124
|
| 290 |
+
208 30
|
| 291 |
+
208 50
|
| 292 |
+
210 38
|
| 293 |
+
210 207
|
| 294 |
+
211 37
|
| 295 |
+
213 35
|
| 296 |
+
213 38
|
| 297 |
+
214 13
|
| 298 |
+
214 14
|
| 299 |
+
214 171
|
| 300 |
+
214 213
|
| 301 |
+
215 75
|
| 302 |
+
217 39
|
| 303 |
+
218 68
|
| 304 |
+
218 222
|
| 305 |
+
221 198
|
| 306 |
+
222 198
|
| 307 |
+
222 218
|
| 308 |
+
223 39
|
| 309 |
+
225 3
|
| 310 |
+
226 22
|
| 311 |
+
229 65
|
| 312 |
+
230 68
|
| 313 |
+
231 43
|
| 314 |
+
232 95
|
| 315 |
+
232 203
|
| 316 |
+
233 99
|
| 317 |
+
234 68
|
| 318 |
+
234 230
|
| 319 |
+
237 244
|
| 320 |
+
238 145
|
| 321 |
+
242 3
|
| 322 |
+
242 113
|
| 323 |
+
244 237
|
| 324 |
+
249 96
|
| 325 |
+
250 156
|
| 326 |
+
252 65
|
| 327 |
+
254 65
|
| 328 |
+
258 113
|
| 329 |
+
268 4
|
| 330 |
+
270 183
|
| 331 |
+
272 6
|
| 332 |
+
275 96
|
| 333 |
+
280 183
|
| 334 |
+
280 206
|
| 335 |
+
282 37
|
| 336 |
+
285 75
|
| 337 |
+
290 285
|
| 338 |
+
293 290
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_beam_search.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===========
|
| 3 |
+
Beam Search
|
| 4 |
+
===========
|
| 5 |
+
|
| 6 |
+
Beam search with dynamic beam width.
|
| 7 |
+
|
| 8 |
+
The progressive widening beam search repeatedly executes a beam search
|
| 9 |
+
with increasing beam width until the target node is found.
|
| 10 |
+
"""
|
| 11 |
+
import math
|
| 12 |
+
|
| 13 |
+
import matplotlib.pyplot as plt
|
| 14 |
+
import networkx as nx
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def progressive_widening_search(G, source, value, condition, initial_width=1):
|
| 18 |
+
"""Progressive widening beam search to find a node.
|
| 19 |
+
|
| 20 |
+
The progressive widening beam search involves a repeated beam
|
| 21 |
+
search, starting with a small beam width then extending to
|
| 22 |
+
progressively larger beam widths if the target node is not
|
| 23 |
+
found. This implementation simply returns the first node found that
|
| 24 |
+
matches the termination condition.
|
| 25 |
+
|
| 26 |
+
`G` is a NetworkX graph.
|
| 27 |
+
|
| 28 |
+
`source` is a node in the graph. The search for the node of interest
|
| 29 |
+
begins here and extends only to those nodes in the (weakly)
|
| 30 |
+
connected component of this node.
|
| 31 |
+
|
| 32 |
+
`value` is a function that returns a real number indicating how good
|
| 33 |
+
a potential neighbor node is when deciding which neighbor nodes to
|
| 34 |
+
enqueue in the breadth-first search. Only the best nodes within the
|
| 35 |
+
current beam width will be enqueued at each step.
|
| 36 |
+
|
| 37 |
+
`condition` is the termination condition for the search. This is a
|
| 38 |
+
function that takes a node as input and return a Boolean indicating
|
| 39 |
+
whether the node is the target. If no node matches the termination
|
| 40 |
+
condition, this function raises :exc:`NodeNotFound`.
|
| 41 |
+
|
| 42 |
+
`initial_width` is the starting beam width for the beam search (the
|
| 43 |
+
default is one). If no node matching the `condition` is found with
|
| 44 |
+
this beam width, the beam search is restarted from the `source` node
|
| 45 |
+
with a beam width that is twice as large (so the beam width
|
| 46 |
+
increases exponentially). The search terminates after the beam width
|
| 47 |
+
exceeds the number of nodes in the graph.
|
| 48 |
+
|
| 49 |
+
"""
|
| 50 |
+
# Check for the special case in which the source node satisfies the
|
| 51 |
+
# termination condition.
|
| 52 |
+
if condition(source):
|
| 53 |
+
return source
|
| 54 |
+
# The largest possible value of `i` in this range yields a width at
|
| 55 |
+
# least the number of nodes in the graph, so the final invocation of
|
| 56 |
+
# `bfs_beam_edges` is equivalent to a plain old breadth-first
|
| 57 |
+
# search. Therefore, all nodes will eventually be visited.
|
| 58 |
+
log_m = math.ceil(math.log2(len(G)))
|
| 59 |
+
for i in range(log_m):
|
| 60 |
+
width = initial_width * pow(2, i)
|
| 61 |
+
# Since we are always starting from the same source node, this
|
| 62 |
+
# search may visit the same nodes many times (depending on the
|
| 63 |
+
# implementation of the `value` function).
|
| 64 |
+
for u, v in nx.bfs_beam_edges(G, source, value, width):
|
| 65 |
+
if condition(v):
|
| 66 |
+
return v
|
| 67 |
+
# At this point, since all nodes have been visited, we know that
|
| 68 |
+
# none of the nodes satisfied the termination condition.
|
| 69 |
+
raise nx.NodeNotFound("no node satisfied the termination condition")
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
###############################################################################
|
| 73 |
+
# Search for a node with high centrality.
|
| 74 |
+
# ---------------------------------------
|
| 75 |
+
#
|
| 76 |
+
# We generate a random graph, compute the centrality of each node, then perform
|
| 77 |
+
# the progressive widening search in order to find a node of high centrality.
|
| 78 |
+
|
| 79 |
+
# Set a seed for random number generation so the example is reproducible
|
| 80 |
+
seed = 89
|
| 81 |
+
|
| 82 |
+
G = nx.gnp_random_graph(100, 0.5, seed=seed)
|
| 83 |
+
centrality = nx.eigenvector_centrality(G)
|
| 84 |
+
avg_centrality = sum(centrality.values()) / len(G)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def has_high_centrality(v):
|
| 88 |
+
return centrality[v] >= avg_centrality
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
source = 0
|
| 92 |
+
value = centrality.get
|
| 93 |
+
condition = has_high_centrality
|
| 94 |
+
|
| 95 |
+
found_node = progressive_widening_search(G, source, value, condition)
|
| 96 |
+
c = centrality[found_node]
|
| 97 |
+
print(f"found node {found_node} with centrality {c}")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# Draw graph
|
| 101 |
+
pos = nx.spring_layout(G, seed=seed)
|
| 102 |
+
options = {
|
| 103 |
+
"node_color": "blue",
|
| 104 |
+
"node_size": 20,
|
| 105 |
+
"edge_color": "grey",
|
| 106 |
+
"linewidths": 0,
|
| 107 |
+
"width": 0.1,
|
| 108 |
+
}
|
| 109 |
+
nx.draw(G, pos, **options)
|
| 110 |
+
# Draw node with high centrality as large and red
|
| 111 |
+
nx.draw_networkx_nodes(G, pos, nodelist=[found_node], node_size=100, node_color="r")
|
| 112 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_betweenness_centrality.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=====================
|
| 3 |
+
Betweeness Centrality
|
| 4 |
+
=====================
|
| 5 |
+
|
| 6 |
+
Betweenness centrality measures of positive gene functional associations
|
| 7 |
+
using WormNet v.3-GS.
|
| 8 |
+
|
| 9 |
+
Data from: https://www.inetbio.org/wormnet/downloadnetwork.php
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from random import sample
|
| 13 |
+
import networkx as nx
|
| 14 |
+
import matplotlib.pyplot as plt
|
| 15 |
+
|
| 16 |
+
# Gold standard data of positive gene functional associations
|
| 17 |
+
# from https://www.inetbio.org/wormnet/downloadnetwork.php
|
| 18 |
+
G = nx.read_edgelist("WormNet.v3.benchmark.txt")
|
| 19 |
+
|
| 20 |
+
# remove randomly selected nodes (to make example fast)
|
| 21 |
+
num_to_remove = int(len(G) / 1.5)
|
| 22 |
+
nodes = sample(list(G.nodes), num_to_remove)
|
| 23 |
+
G.remove_nodes_from(nodes)
|
| 24 |
+
|
| 25 |
+
# remove low-degree nodes
|
| 26 |
+
low_degree = [n for n, d in G.degree() if d < 10]
|
| 27 |
+
G.remove_nodes_from(low_degree)
|
| 28 |
+
|
| 29 |
+
# largest connected component
|
| 30 |
+
components = nx.connected_components(G)
|
| 31 |
+
largest_component = max(components, key=len)
|
| 32 |
+
H = G.subgraph(largest_component)
|
| 33 |
+
|
| 34 |
+
# compute centrality
|
| 35 |
+
centrality = nx.betweenness_centrality(H, k=10, endpoints=True)
|
| 36 |
+
|
| 37 |
+
# compute community structure
|
| 38 |
+
lpc = nx.community.label_propagation_communities(H)
|
| 39 |
+
community_index = {n: i for i, com in enumerate(lpc) for n in com}
|
| 40 |
+
|
| 41 |
+
#### draw graph ####
|
| 42 |
+
fig, ax = plt.subplots(figsize=(20, 15))
|
| 43 |
+
pos = nx.spring_layout(H, k=0.15, seed=4572321)
|
| 44 |
+
node_color = [community_index[n] for n in H]
|
| 45 |
+
node_size = [v * 20000 for v in centrality.values()]
|
| 46 |
+
nx.draw_networkx(
|
| 47 |
+
H,
|
| 48 |
+
pos=pos,
|
| 49 |
+
with_labels=False,
|
| 50 |
+
node_color=node_color,
|
| 51 |
+
node_size=node_size,
|
| 52 |
+
edge_color="gainsboro",
|
| 53 |
+
alpha=0.4,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Title/legend
|
| 57 |
+
font = {"color": "k", "fontweight": "bold", "fontsize": 20}
|
| 58 |
+
ax.set_title("Gene functional association network (C. elegans)", font)
|
| 59 |
+
# Change font color for legend
|
| 60 |
+
font["color"] = "r"
|
| 61 |
+
|
| 62 |
+
ax.text(
|
| 63 |
+
0.80,
|
| 64 |
+
0.10,
|
| 65 |
+
"node color = community structure",
|
| 66 |
+
horizontalalignment="center",
|
| 67 |
+
transform=ax.transAxes,
|
| 68 |
+
fontdict=font,
|
| 69 |
+
)
|
| 70 |
+
ax.text(
|
| 71 |
+
0.80,
|
| 72 |
+
0.06,
|
| 73 |
+
"node size = betweeness centrality",
|
| 74 |
+
horizontalalignment="center",
|
| 75 |
+
transform=ax.transAxes,
|
| 76 |
+
fontdict=font,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
# Resize figure for label readibility
|
| 80 |
+
ax.margins(0.1, 0.05)
|
| 81 |
+
fig.tight_layout()
|
| 82 |
+
plt.axis("off")
|
| 83 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_blockmodel.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==========
|
| 3 |
+
Blockmodel
|
| 4 |
+
==========
|
| 5 |
+
|
| 6 |
+
Example of creating a block model using the quotient_graph function in NX. Data
|
| 7 |
+
used is the Hartford, CT drug users network::
|
| 8 |
+
|
| 9 |
+
@article{weeks2002social,
|
| 10 |
+
title={Social networks of drug users in high-risk sites: Finding the connections},
|
| 11 |
+
url = {https://doi.org/10.1023/A:1015457400897},
|
| 12 |
+
doi = {10.1023/A:1015457400897},
|
| 13 |
+
author={Weeks, Margaret R and Clair, Scott and Borgatti, Stephen P and Radda, Kim and Schensul, Jean J},
|
| 14 |
+
journal={{AIDS and Behavior}},
|
| 15 |
+
volume={6},
|
| 16 |
+
number={2},
|
| 17 |
+
pages={193--206},
|
| 18 |
+
year={2002},
|
| 19 |
+
publisher={Springer}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
from collections import defaultdict
|
| 25 |
+
|
| 26 |
+
import matplotlib.pyplot as plt
|
| 27 |
+
import networkx as nx
|
| 28 |
+
import numpy as np
|
| 29 |
+
from scipy.cluster import hierarchy
|
| 30 |
+
from scipy.spatial import distance
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def create_hc(G):
|
| 34 |
+
"""Creates hierarchical cluster of graph G from distance matrix"""
|
| 35 |
+
path_length = nx.all_pairs_shortest_path_length(G)
|
| 36 |
+
distances = np.zeros((len(G), len(G)))
|
| 37 |
+
for u, p in path_length:
|
| 38 |
+
for v, d in p.items():
|
| 39 |
+
distances[u][v] = d
|
| 40 |
+
# Create hierarchical cluster
|
| 41 |
+
Y = distance.squareform(distances)
|
| 42 |
+
Z = hierarchy.complete(Y) # Creates HC using farthest point linkage
|
| 43 |
+
# This partition selection is arbitrary, for illustrive purposes
|
| 44 |
+
membership = list(hierarchy.fcluster(Z, t=1.15))
|
| 45 |
+
# Create collection of lists for blockmodel
|
| 46 |
+
partition = defaultdict(list)
|
| 47 |
+
for n, p in zip(list(range(len(G))), membership):
|
| 48 |
+
partition[p].append(n)
|
| 49 |
+
return list(partition.values())
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
G = nx.read_edgelist("hartford_drug.edgelist")
|
| 53 |
+
|
| 54 |
+
# Extract largest connected component into graph H
|
| 55 |
+
H = G.subgraph(next(nx.connected_components(G)))
|
| 56 |
+
# Makes life easier to have consecutively labeled integer nodes
|
| 57 |
+
H = nx.convert_node_labels_to_integers(H)
|
| 58 |
+
# Create parititions with hierarchical clustering
|
| 59 |
+
partitions = create_hc(H)
|
| 60 |
+
# Build blockmodel graph
|
| 61 |
+
BM = nx.quotient_graph(H, partitions, relabel=True)
|
| 62 |
+
|
| 63 |
+
# Draw original graph
|
| 64 |
+
pos = nx.spring_layout(H, iterations=100, seed=83) # Seed for reproducibility
|
| 65 |
+
plt.subplot(211)
|
| 66 |
+
nx.draw(H, pos, with_labels=False, node_size=10)
|
| 67 |
+
|
| 68 |
+
# Draw block model with weighted edges and nodes sized by number of internal nodes
|
| 69 |
+
node_size = [BM.nodes[x]["nnodes"] * 10 for x in BM.nodes()]
|
| 70 |
+
edge_width = [(2 * d["weight"]) for (u, v, d) in BM.edges(data=True)]
|
| 71 |
+
# Set positions to mean of positions of internal nodes from original graph
|
| 72 |
+
posBM = {}
|
| 73 |
+
for n in BM:
|
| 74 |
+
xy = np.array([pos[u] for u in BM.nodes[n]["graph"]])
|
| 75 |
+
posBM[n] = xy.mean(axis=0)
|
| 76 |
+
plt.subplot(212)
|
| 77 |
+
nx.draw(BM, posBM, node_size=node_size, width=edge_width, with_labels=False)
|
| 78 |
+
plt.axis("off")
|
| 79 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_circuits.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
========
|
| 3 |
+
Circuits
|
| 4 |
+
========
|
| 5 |
+
|
| 6 |
+
Convert a Boolean circuit to an equivalent Boolean formula.
|
| 7 |
+
|
| 8 |
+
A Boolean circuit can be exponentially more expressive than an
|
| 9 |
+
equivalent formula in the worst case, since the circuit can reuse
|
| 10 |
+
subcircuits multiple times, whereas a formula cannot reuse subformulas
|
| 11 |
+
more than once. Thus creating a Boolean formula from a Boolean circuit
|
| 12 |
+
in this way may be infeasible if the circuit is large.
|
| 13 |
+
|
| 14 |
+
"""
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
+
import networkx as nx
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def circuit_to_formula(circuit):
|
| 20 |
+
# Convert the circuit to an equivalent formula.
|
| 21 |
+
formula = nx.dag_to_branching(circuit)
|
| 22 |
+
# Transfer the operator or variable labels for each node from the
|
| 23 |
+
# circuit to the formula.
|
| 24 |
+
for v in formula:
|
| 25 |
+
source = formula.nodes[v]["source"]
|
| 26 |
+
formula.nodes[v]["label"] = circuit.nodes[source]["label"]
|
| 27 |
+
return formula
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def formula_to_string(formula):
|
| 31 |
+
def _to_string(formula, root):
|
| 32 |
+
# If there are no children, this is a variable node.
|
| 33 |
+
label = formula.nodes[root]["label"]
|
| 34 |
+
if not formula[root]:
|
| 35 |
+
return label
|
| 36 |
+
# Otherwise, this is an operator.
|
| 37 |
+
children = formula[root]
|
| 38 |
+
# If one child, the label must be a NOT operator.
|
| 39 |
+
if len(children) == 1:
|
| 40 |
+
child = nx.utils.arbitrary_element(children)
|
| 41 |
+
return f"{label}({_to_string(formula, child)})"
|
| 42 |
+
# NB "left" and "right" here are a little misleading: there is
|
| 43 |
+
# no order on the children of a node. That's okay because the
|
| 44 |
+
# Boolean AND and OR operators are symmetric. It just means that
|
| 45 |
+
# the order of the operands cannot be predicted and hence the
|
| 46 |
+
# function does not necessarily behave the same way on every
|
| 47 |
+
# invocation.
|
| 48 |
+
left, right = formula[root]
|
| 49 |
+
left_subformula = _to_string(formula, left)
|
| 50 |
+
right_subformula = _to_string(formula, right)
|
| 51 |
+
return f"({left_subformula} {label} {right_subformula})"
|
| 52 |
+
|
| 53 |
+
root = next(v for v, d in formula.in_degree() if d == 0)
|
| 54 |
+
return _to_string(formula, root)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
###############################################################################
|
| 58 |
+
# Create an example Boolean circuit.
|
| 59 |
+
# ----------------------------------
|
| 60 |
+
#
|
| 61 |
+
# This circuit has a ∧ at the output and two ∨s at the next layer.
|
| 62 |
+
# The third layer has a variable x that appears in the left ∨, a
|
| 63 |
+
# variable y that appears in both the left and right ∨s, and a
|
| 64 |
+
# negation for the variable z that appears as the sole node in the
|
| 65 |
+
# fourth layer.
|
| 66 |
+
circuit = nx.DiGraph()
|
| 67 |
+
# Layer 0
|
| 68 |
+
circuit.add_node(0, label="∧", layer=0)
|
| 69 |
+
# Layer 1
|
| 70 |
+
circuit.add_node(1, label="∨", layer=1)
|
| 71 |
+
circuit.add_node(2, label="∨", layer=1)
|
| 72 |
+
circuit.add_edge(0, 1)
|
| 73 |
+
circuit.add_edge(0, 2)
|
| 74 |
+
# Layer 2
|
| 75 |
+
circuit.add_node(3, label="x", layer=2)
|
| 76 |
+
circuit.add_node(4, label="y", layer=2)
|
| 77 |
+
circuit.add_node(5, label="¬", layer=2)
|
| 78 |
+
circuit.add_edge(1, 3)
|
| 79 |
+
circuit.add_edge(1, 4)
|
| 80 |
+
circuit.add_edge(2, 4)
|
| 81 |
+
circuit.add_edge(2, 5)
|
| 82 |
+
# Layer 3
|
| 83 |
+
circuit.add_node(6, label="z", layer=3)
|
| 84 |
+
circuit.add_edge(5, 6)
|
| 85 |
+
# Convert the circuit to an equivalent formula.
|
| 86 |
+
formula = circuit_to_formula(circuit)
|
| 87 |
+
print(formula_to_string(formula))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
labels = nx.get_node_attributes(circuit, "label")
|
| 91 |
+
options = {
|
| 92 |
+
"node_size": 600,
|
| 93 |
+
"alpha": 0.5,
|
| 94 |
+
"node_color": "blue",
|
| 95 |
+
"labels": labels,
|
| 96 |
+
"font_size": 22,
|
| 97 |
+
}
|
| 98 |
+
plt.figure(figsize=(8, 8))
|
| 99 |
+
pos = nx.multipartite_layout(circuit, subset_key="layer")
|
| 100 |
+
nx.draw_networkx(circuit, pos, **options)
|
| 101 |
+
plt.title(formula_to_string(formula))
|
| 102 |
+
plt.axis("equal")
|
| 103 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_davis_club.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==========
|
| 3 |
+
Davis Club
|
| 4 |
+
==========
|
| 5 |
+
|
| 6 |
+
Davis Southern Club Women
|
| 7 |
+
|
| 8 |
+
Shows how to make unipartite projections of the graph and compute the
|
| 9 |
+
properties of those graphs.
|
| 10 |
+
|
| 11 |
+
These data were collected by Davis et al. in the 1930s.
|
| 12 |
+
They represent observed attendance at 14 social events by 18 Southern women.
|
| 13 |
+
The graph is bipartite (clubs, women).
|
| 14 |
+
"""
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
+
import networkx as nx
|
| 17 |
+
import networkx.algorithms.bipartite as bipartite
|
| 18 |
+
|
| 19 |
+
G = nx.davis_southern_women_graph()
|
| 20 |
+
women = G.graph["top"]
|
| 21 |
+
clubs = G.graph["bottom"]
|
| 22 |
+
|
| 23 |
+
print("Biadjacency matrix")
|
| 24 |
+
print(bipartite.biadjacency_matrix(G, women, clubs))
|
| 25 |
+
|
| 26 |
+
# project bipartite graph onto women nodes
|
| 27 |
+
W = bipartite.projected_graph(G, women)
|
| 28 |
+
print()
|
| 29 |
+
print("#Friends, Member")
|
| 30 |
+
for w in women:
|
| 31 |
+
print(f"{W.degree(w)} {w}")
|
| 32 |
+
|
| 33 |
+
# project bipartite graph onto women nodes keeping number of co-occurence
|
| 34 |
+
# the degree computed is weighted and counts the total number of shared contacts
|
| 35 |
+
W = bipartite.weighted_projected_graph(G, women)
|
| 36 |
+
print()
|
| 37 |
+
print("#Friend meetings, Member")
|
| 38 |
+
for w in women:
|
| 39 |
+
print(f"{W.degree(w, weight='weight')} {w}")
|
| 40 |
+
|
| 41 |
+
pos = nx.spring_layout(G, seed=648) # Seed layout for reproducible node positions
|
| 42 |
+
nx.draw(G, pos)
|
| 43 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_dedensification.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===============
|
| 3 |
+
Dedensification
|
| 4 |
+
===============
|
| 5 |
+
|
| 6 |
+
Examples of dedensification of a graph. Dedensification retains the structural
|
| 7 |
+
pattern of the original graph and will only add compressor nodes when doing so
|
| 8 |
+
would result in fewer edges in the compressed graph.
|
| 9 |
+
"""
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
import networkx as nx
|
| 12 |
+
|
| 13 |
+
plt.suptitle("Dedensification")
|
| 14 |
+
|
| 15 |
+
original_graph = nx.DiGraph()
|
| 16 |
+
white_nodes = ["1", "2", "3", "4", "5", "6"]
|
| 17 |
+
red_nodes = ["A", "B", "C"]
|
| 18 |
+
node_sizes = [250 for node in white_nodes + red_nodes]
|
| 19 |
+
node_colors = ["white" for n in white_nodes] + ["red" for n in red_nodes]
|
| 20 |
+
|
| 21 |
+
original_graph.add_nodes_from(white_nodes + red_nodes)
|
| 22 |
+
original_graph.add_edges_from(
|
| 23 |
+
[
|
| 24 |
+
("1", "C"),
|
| 25 |
+
("1", "B"),
|
| 26 |
+
("2", "C"),
|
| 27 |
+
("2", "B"),
|
| 28 |
+
("2", "A"),
|
| 29 |
+
("3", "B"),
|
| 30 |
+
("3", "A"),
|
| 31 |
+
("3", "6"),
|
| 32 |
+
("4", "C"),
|
| 33 |
+
("4", "B"),
|
| 34 |
+
("4", "A"),
|
| 35 |
+
("5", "B"),
|
| 36 |
+
("5", "A"),
|
| 37 |
+
("6", "5"),
|
| 38 |
+
("A", "6"),
|
| 39 |
+
]
|
| 40 |
+
)
|
| 41 |
+
base_options = dict(with_labels=True, edgecolors="black")
|
| 42 |
+
pos = {
|
| 43 |
+
"3": (0, 1),
|
| 44 |
+
"2": (0, 2),
|
| 45 |
+
"1": (0, 3),
|
| 46 |
+
"6": (1, 0),
|
| 47 |
+
"A": (1, 1),
|
| 48 |
+
"B": (1, 2),
|
| 49 |
+
"C": (1, 3),
|
| 50 |
+
"4": (2, 3),
|
| 51 |
+
"5": (2, 1),
|
| 52 |
+
}
|
| 53 |
+
ax1 = plt.subplot(1, 2, 1)
|
| 54 |
+
plt.title("Original (%s edges)" % original_graph.number_of_edges())
|
| 55 |
+
nx.draw_networkx(original_graph, pos=pos, node_color=node_colors, **base_options)
|
| 56 |
+
|
| 57 |
+
nonexp_graph, compression_nodes = nx.summarization.dedensify(
|
| 58 |
+
original_graph, threshold=2, copy=False
|
| 59 |
+
)
|
| 60 |
+
nonexp_node_colors = list(node_colors)
|
| 61 |
+
nonexp_node_sizes = list(node_sizes)
|
| 62 |
+
for node in compression_nodes:
|
| 63 |
+
nonexp_node_colors.append("yellow")
|
| 64 |
+
nonexp_node_sizes.append(600)
|
| 65 |
+
plt.subplot(1, 2, 2)
|
| 66 |
+
|
| 67 |
+
plt.title("Dedensified (%s edges)" % nonexp_graph.number_of_edges())
|
| 68 |
+
nonexp_pos = {
|
| 69 |
+
"5": (0, 0),
|
| 70 |
+
"B": (0, 2),
|
| 71 |
+
"1": (0, 3),
|
| 72 |
+
"6": (1, 0.75),
|
| 73 |
+
"3": (1.5, 1.5),
|
| 74 |
+
"A": (2, 0),
|
| 75 |
+
"C": (2, 3),
|
| 76 |
+
"4": (3, 1.5),
|
| 77 |
+
"2": (3, 2.5),
|
| 78 |
+
}
|
| 79 |
+
c_nodes = list(compression_nodes)
|
| 80 |
+
c_nodes.sort()
|
| 81 |
+
for spot, node in enumerate(c_nodes):
|
| 82 |
+
nonexp_pos[node] = (2, spot + 2)
|
| 83 |
+
nx.draw_networkx(
|
| 84 |
+
nonexp_graph,
|
| 85 |
+
pos=nonexp_pos,
|
| 86 |
+
node_color=nonexp_node_colors,
|
| 87 |
+
node_size=nonexp_node_sizes,
|
| 88 |
+
**base_options
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
plt.tight_layout()
|
| 92 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_iterated_dynamical_systems.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==========================
|
| 3 |
+
Iterated Dynamical Systems
|
| 4 |
+
==========================
|
| 5 |
+
|
| 6 |
+
Digraphs from Integer-valued Iterated Functions
|
| 7 |
+
|
| 8 |
+
Sums of cubes on 3N
|
| 9 |
+
-------------------
|
| 10 |
+
|
| 11 |
+
The number 153 has a curious property.
|
| 12 |
+
|
| 13 |
+
Let 3N={3,6,9,12,...} be the set of positive multiples of 3. Define an
|
| 14 |
+
iterative process f:3N->3N as follows: for a given n, take each digit
|
| 15 |
+
of n (in base 10), cube it and then sum the cubes to obtain f(n).
|
| 16 |
+
|
| 17 |
+
When this process is repeated, the resulting series n, f(n), f(f(n)),...
|
| 18 |
+
terminate in 153 after a finite number of iterations (the process ends
|
| 19 |
+
because 153 = 1**3 + 5**3 + 3**3).
|
| 20 |
+
|
| 21 |
+
In the language of discrete dynamical systems, 153 is the global
|
| 22 |
+
attractor for the iterated map f restricted to the set 3N.
|
| 23 |
+
|
| 24 |
+
For example: take the number 108
|
| 25 |
+
|
| 26 |
+
f(108) = 1**3 + 0**3 + 8**3 = 513
|
| 27 |
+
|
| 28 |
+
and
|
| 29 |
+
|
| 30 |
+
f(513) = 5**3 + 1**3 + 3**3 = 153
|
| 31 |
+
|
| 32 |
+
So, starting at 108 we reach 153 in two iterations,
|
| 33 |
+
represented as:
|
| 34 |
+
|
| 35 |
+
108->513->153
|
| 36 |
+
|
| 37 |
+
Computing all orbits of 3N up to 10**5 reveals that the attractor
|
| 38 |
+
153 is reached in a maximum of 14 iterations. In this code we
|
| 39 |
+
show that 13 cycles is the maximum required for all integers (in 3N)
|
| 40 |
+
less than 10,000.
|
| 41 |
+
|
| 42 |
+
The smallest number that requires 13 iterations to reach 153, is 177, i.e.,
|
| 43 |
+
|
| 44 |
+
177->687->1071->345->216->225->141->66->432->99->1458->702->351->153
|
| 45 |
+
|
| 46 |
+
The resulting large digraphs are useful for testing network software.
|
| 47 |
+
|
| 48 |
+
The general problem
|
| 49 |
+
-------------------
|
| 50 |
+
|
| 51 |
+
Given numbers n, a power p and base b, define F(n; p, b) as the sum of
|
| 52 |
+
the digits of n (in base b) raised to the power p. The above example
|
| 53 |
+
corresponds to f(n)=F(n; 3,10), and below F(n; p, b) is implemented as
|
| 54 |
+
the function powersum(n,p,b). The iterative dynamical system defined by
|
| 55 |
+
the mapping n:->f(n) above (over 3N) converges to a single fixed point;
|
| 56 |
+
153. Applying the map to all positive integers N, leads to a discrete
|
| 57 |
+
dynamical process with 5 fixed points: 1, 153, 370, 371, 407. Modulo 3
|
| 58 |
+
those numbers are 1, 0, 1, 2, 2. The function f above has the added
|
| 59 |
+
property that it maps a multiple of 3 to another multiple of 3; i.e. it
|
| 60 |
+
is invariant on the subset 3N.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
The squaring of digits (in base 10) result in cycles and the
|
| 64 |
+
single fixed point 1. I.e., from a certain point on, the process
|
| 65 |
+
starts repeating itself.
|
| 66 |
+
|
| 67 |
+
keywords: "Recurring Digital Invariant", "Narcissistic Number",
|
| 68 |
+
"Happy Number"
|
| 69 |
+
|
| 70 |
+
The 3n+1 problem
|
| 71 |
+
----------------
|
| 72 |
+
|
| 73 |
+
There is a rich history of mathematical recreations
|
| 74 |
+
associated with discrete dynamical systems. The most famous
|
| 75 |
+
is the Collatz 3n+1 problem. See the function
|
| 76 |
+
collatz_problem_digraph below. The Collatz conjecture
|
| 77 |
+
--- that every orbit returns to the fixed point 1 in finite time
|
| 78 |
+
--- is still unproven. Even the great Paul Erdos said "Mathematics
|
| 79 |
+
is not yet ready for such problems", and offered $500
|
| 80 |
+
for its solution.
|
| 81 |
+
|
| 82 |
+
keywords: "3n+1", "3x+1", "Collatz problem", "Thwaite's conjecture"
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
import networkx as nx
|
| 86 |
+
|
| 87 |
+
nmax = 10000
|
| 88 |
+
p = 3
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def digitsrep(n, b=10):
|
| 92 |
+
"""Return list of digits comprising n represented in base b.
|
| 93 |
+
n must be a nonnegative integer"""
|
| 94 |
+
|
| 95 |
+
if n <= 0:
|
| 96 |
+
return [0]
|
| 97 |
+
|
| 98 |
+
dlist = []
|
| 99 |
+
while n > 0:
|
| 100 |
+
# Prepend next least-significant digit
|
| 101 |
+
dlist = [n % b] + dlist
|
| 102 |
+
# Floor-division
|
| 103 |
+
n = n // b
|
| 104 |
+
return dlist
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def powersum(n, p, b=10):
|
| 108 |
+
"""Return sum of digits of n (in base b) raised to the power p."""
|
| 109 |
+
dlist = digitsrep(n, b)
|
| 110 |
+
sum = 0
|
| 111 |
+
for k in dlist:
|
| 112 |
+
sum += k ** p
|
| 113 |
+
return sum
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def attractor153_graph(n, p, multiple=3, b=10):
|
| 117 |
+
"""Return digraph of iterations of powersum(n,3,10)."""
|
| 118 |
+
G = nx.DiGraph()
|
| 119 |
+
for k in range(1, n + 1):
|
| 120 |
+
if k % multiple == 0 and k not in G:
|
| 121 |
+
k1 = k
|
| 122 |
+
knext = powersum(k1, p, b)
|
| 123 |
+
while k1 != knext:
|
| 124 |
+
G.add_edge(k1, knext)
|
| 125 |
+
k1 = knext
|
| 126 |
+
knext = powersum(k1, p, b)
|
| 127 |
+
return G
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def squaring_cycle_graph_old(n, b=10):
|
| 131 |
+
"""Return digraph of iterations of powersum(n,2,10)."""
|
| 132 |
+
G = nx.DiGraph()
|
| 133 |
+
for k in range(1, n + 1):
|
| 134 |
+
k1 = k
|
| 135 |
+
G.add_node(k1) # case k1==knext, at least add node
|
| 136 |
+
knext = powersum(k1, 2, b)
|
| 137 |
+
G.add_edge(k1, knext)
|
| 138 |
+
while k1 != knext: # stop if fixed point
|
| 139 |
+
k1 = knext
|
| 140 |
+
knext = powersum(k1, 2, b)
|
| 141 |
+
G.add_edge(k1, knext)
|
| 142 |
+
if G.out_degree(knext) >= 1:
|
| 143 |
+
# knext has already been iterated in and out
|
| 144 |
+
break
|
| 145 |
+
return G
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def sum_of_digits_graph(nmax, b=10):
|
| 149 |
+
def f(n):
|
| 150 |
+
return powersum(n, 1, b)
|
| 151 |
+
|
| 152 |
+
return discrete_dynamics_digraph(nmax, f)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def squaring_cycle_digraph(nmax, b=10):
|
| 156 |
+
def f(n):
|
| 157 |
+
return powersum(n, 2, b)
|
| 158 |
+
|
| 159 |
+
return discrete_dynamics_digraph(nmax, f)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def cubing_153_digraph(nmax):
|
| 163 |
+
def f(n):
|
| 164 |
+
return powersum(n, 3, 10)
|
| 165 |
+
|
| 166 |
+
return discrete_dynamics_digraph(nmax, f)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def discrete_dynamics_digraph(nmax, f, itermax=50000):
|
| 170 |
+
G = nx.DiGraph()
|
| 171 |
+
for k in range(1, nmax + 1):
|
| 172 |
+
kold = k
|
| 173 |
+
G.add_node(kold)
|
| 174 |
+
knew = f(kold)
|
| 175 |
+
G.add_edge(kold, knew)
|
| 176 |
+
while kold != knew and kold << itermax:
|
| 177 |
+
# iterate until fixed point reached or itermax is exceeded
|
| 178 |
+
kold = knew
|
| 179 |
+
knew = f(kold)
|
| 180 |
+
G.add_edge(kold, knew)
|
| 181 |
+
if G.out_degree(knew) >= 1:
|
| 182 |
+
# knew has already been iterated in and out
|
| 183 |
+
break
|
| 184 |
+
return G
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def collatz_problem_digraph(nmax):
|
| 188 |
+
def f(n):
|
| 189 |
+
if n % 2 == 0:
|
| 190 |
+
return n // 2
|
| 191 |
+
else:
|
| 192 |
+
return 3 * n + 1
|
| 193 |
+
|
| 194 |
+
return discrete_dynamics_digraph(nmax, f)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def fixed_points(G):
|
| 198 |
+
"""Return a list of fixed points for the discrete dynamical
|
| 199 |
+
system represented by the digraph G.
|
| 200 |
+
"""
|
| 201 |
+
return [n for n in G if G.out_degree(n) == 0]
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
nmax = 10000
|
| 205 |
+
print(f"Building cubing_153_digraph({nmax})")
|
| 206 |
+
G = cubing_153_digraph(nmax)
|
| 207 |
+
print("Resulting digraph has", len(G), "nodes and", G.size(), " edges")
|
| 208 |
+
print("Shortest path from 177 to 153 is:")
|
| 209 |
+
print(nx.shortest_path(G, 177, 153))
|
| 210 |
+
print(f"fixed points are {fixed_points(G)}")
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_krackhardt_centrality.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=====================
|
| 3 |
+
Krackhardt Centrality
|
| 4 |
+
=====================
|
| 5 |
+
|
| 6 |
+
Centrality measures of Krackhardt social network.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.krackhardt_kite_graph()
|
| 13 |
+
|
| 14 |
+
print("Betweenness")
|
| 15 |
+
b = nx.betweenness_centrality(G)
|
| 16 |
+
for v in G.nodes():
|
| 17 |
+
print(f"{v:2} {b[v]:.3f}")
|
| 18 |
+
|
| 19 |
+
print("Degree centrality")
|
| 20 |
+
d = nx.degree_centrality(G)
|
| 21 |
+
for v in G.nodes():
|
| 22 |
+
print(f"{v:2} {d[v]:.3f}")
|
| 23 |
+
|
| 24 |
+
print("Closeness centrality")
|
| 25 |
+
c = nx.closeness_centrality(G)
|
| 26 |
+
for v in G.nodes():
|
| 27 |
+
print(f"{v:2} {c[v]:.3f}")
|
| 28 |
+
|
| 29 |
+
pos = nx.spring_layout(G, seed=367) # Seed layout for reproducibility
|
| 30 |
+
nx.draw(G, pos)
|
| 31 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_parallel_betweenness.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
====================
|
| 3 |
+
Parallel Betweenness
|
| 4 |
+
====================
|
| 5 |
+
|
| 6 |
+
Example of parallel implementation of betweenness centrality using the
|
| 7 |
+
multiprocessing module from Python Standard Library.
|
| 8 |
+
|
| 9 |
+
The function betweenness centrality accepts a bunch of nodes and computes
|
| 10 |
+
the contribution of those nodes to the betweenness centrality of the whole
|
| 11 |
+
network. Here we divide the network in chunks of nodes and we compute their
|
| 12 |
+
contribution to the betweenness centrality of the whole network.
|
| 13 |
+
|
| 14 |
+
Note: The example output below shows that the non-parallel implementation is
|
| 15 |
+
faster. This is a limitation of our CI/CD pipeline running on a single core.
|
| 16 |
+
|
| 17 |
+
Depending on your setup, you will likely observe a speedup.
|
| 18 |
+
"""
|
| 19 |
+
from multiprocessing import Pool
|
| 20 |
+
import time
|
| 21 |
+
import itertools
|
| 22 |
+
|
| 23 |
+
import matplotlib.pyplot as plt
|
| 24 |
+
import networkx as nx
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def chunks(l, n):
|
| 28 |
+
"""Divide a list of nodes `l` in `n` chunks"""
|
| 29 |
+
l_c = iter(l)
|
| 30 |
+
while 1:
|
| 31 |
+
x = tuple(itertools.islice(l_c, n))
|
| 32 |
+
if not x:
|
| 33 |
+
return
|
| 34 |
+
yield x
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def betweenness_centrality_parallel(G, processes=None):
|
| 38 |
+
"""Parallel betweenness centrality function"""
|
| 39 |
+
p = Pool(processes=processes)
|
| 40 |
+
node_divisor = len(p._pool) * 4
|
| 41 |
+
node_chunks = list(chunks(G.nodes(), int(G.order() / node_divisor)))
|
| 42 |
+
num_chunks = len(node_chunks)
|
| 43 |
+
bt_sc = p.starmap(
|
| 44 |
+
nx.betweenness_centrality_subset,
|
| 45 |
+
zip(
|
| 46 |
+
[G] * num_chunks,
|
| 47 |
+
node_chunks,
|
| 48 |
+
[list(G)] * num_chunks,
|
| 49 |
+
[True] * num_chunks,
|
| 50 |
+
[None] * num_chunks,
|
| 51 |
+
),
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Reduce the partial solutions
|
| 55 |
+
bt_c = bt_sc[0]
|
| 56 |
+
for bt in bt_sc[1:]:
|
| 57 |
+
for n in bt:
|
| 58 |
+
bt_c[n] += bt[n]
|
| 59 |
+
return bt_c
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
G_ba = nx.barabasi_albert_graph(1000, 3)
|
| 63 |
+
G_er = nx.gnp_random_graph(1000, 0.01)
|
| 64 |
+
G_ws = nx.connected_watts_strogatz_graph(1000, 4, 0.1)
|
| 65 |
+
for G in [G_ba, G_er, G_ws]:
|
| 66 |
+
print("")
|
| 67 |
+
print("Computing betweenness centrality for:")
|
| 68 |
+
print(nx.info(G))
|
| 69 |
+
print("\tParallel version")
|
| 70 |
+
start = time.time()
|
| 71 |
+
bt = betweenness_centrality_parallel(G)
|
| 72 |
+
print(f"\t\tTime: {(time.time() - start):.4F} seconds")
|
| 73 |
+
print(f"\t\tBetweenness centrality for node 0: {bt[0]:.5f}")
|
| 74 |
+
print("\tNon-Parallel version")
|
| 75 |
+
start = time.time()
|
| 76 |
+
bt = nx.betweenness_centrality(G)
|
| 77 |
+
print(f"\t\tTime: {(time.time() - start):.4F} seconds")
|
| 78 |
+
print(f"\t\tBetweenness centrality for node 0: {bt[0]:.5f}")
|
| 79 |
+
print("")
|
| 80 |
+
|
| 81 |
+
nx.draw(G_ba, node_size=100)
|
| 82 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_rcm.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
======================
|
| 3 |
+
Reverse Cuthill--McKee
|
| 4 |
+
======================
|
| 5 |
+
|
| 6 |
+
Cuthill-McKee ordering of matrices
|
| 7 |
+
|
| 8 |
+
The reverse Cuthill--McKee algorithm gives a sparse matrix ordering that
|
| 9 |
+
reduces the matrix bandwidth.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import matplotlib.pyplot as plt
|
| 14 |
+
import seaborn as sns
|
| 15 |
+
import networkx as nx
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# build low-bandwidth numpy matrix
|
| 19 |
+
G = nx.grid_2d_graph(3, 3)
|
| 20 |
+
rcm = list(nx.utils.reverse_cuthill_mckee_ordering(G))
|
| 21 |
+
print("ordering", rcm)
|
| 22 |
+
|
| 23 |
+
print("unordered Laplacian matrix")
|
| 24 |
+
A = nx.laplacian_matrix(G)
|
| 25 |
+
x, y = np.nonzero(A)
|
| 26 |
+
# print(f"lower bandwidth: {(y - x).max()}")
|
| 27 |
+
# print(f"upper bandwidth: {(x - y).max()}")
|
| 28 |
+
print(f"bandwidth: {(y - x).max() + (x - y).max() + 1}")
|
| 29 |
+
print(A)
|
| 30 |
+
|
| 31 |
+
B = nx.laplacian_matrix(G, nodelist=rcm)
|
| 32 |
+
print("low-bandwidth Laplacian matrix")
|
| 33 |
+
x, y = np.nonzero(B)
|
| 34 |
+
# print(f"lower bandwidth: {(y - x).max()}")
|
| 35 |
+
# print(f"upper bandwidth: {(x - y).max()}")
|
| 36 |
+
print(f"bandwidth: {(y - x).max() + (x - y).max() + 1}")
|
| 37 |
+
print(B)
|
| 38 |
+
|
| 39 |
+
sns.heatmap(B.todense(), cbar=False, square=True, linewidths=0.5, annot=True)
|
| 40 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/algorithms/plot_snap.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==================
|
| 3 |
+
SNAP Graph Summary
|
| 4 |
+
==================
|
| 5 |
+
An example of summarizing a graph based on node attributes and edge attributes
|
| 6 |
+
using the Summarization by Grouping Nodes on Attributes and Pairwise
|
| 7 |
+
edges (SNAP) algorithm (not to be confused with the Stanford Network
|
| 8 |
+
Analysis Project). The algorithm groups nodes by their unique
|
| 9 |
+
combinations of node attribute values and edge types with other groups
|
| 10 |
+
of nodes to produce a summary graph. The summary graph can then be used to
|
| 11 |
+
infer how nodes with different attributes values relate to other nodes in the
|
| 12 |
+
graph.
|
| 13 |
+
"""
|
| 14 |
+
import networkx as nx
|
| 15 |
+
import matplotlib.pyplot as plt
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
nodes = {
|
| 19 |
+
"A": dict(color="Red"),
|
| 20 |
+
"B": dict(color="Red"),
|
| 21 |
+
"C": dict(color="Red"),
|
| 22 |
+
"D": dict(color="Red"),
|
| 23 |
+
"E": dict(color="Blue"),
|
| 24 |
+
"F": dict(color="Blue"),
|
| 25 |
+
"G": dict(color="Blue"),
|
| 26 |
+
"H": dict(color="Blue"),
|
| 27 |
+
"I": dict(color="Yellow"),
|
| 28 |
+
"J": dict(color="Yellow"),
|
| 29 |
+
"K": dict(color="Yellow"),
|
| 30 |
+
"L": dict(color="Yellow"),
|
| 31 |
+
}
|
| 32 |
+
edges = [
|
| 33 |
+
("A", "B", "Strong"),
|
| 34 |
+
("A", "C", "Weak"),
|
| 35 |
+
("A", "E", "Strong"),
|
| 36 |
+
("A", "I", "Weak"),
|
| 37 |
+
("B", "D", "Weak"),
|
| 38 |
+
("B", "J", "Weak"),
|
| 39 |
+
("B", "F", "Strong"),
|
| 40 |
+
("C", "G", "Weak"),
|
| 41 |
+
("D", "H", "Weak"),
|
| 42 |
+
("I", "J", "Strong"),
|
| 43 |
+
("J", "K", "Strong"),
|
| 44 |
+
("I", "L", "Strong"),
|
| 45 |
+
]
|
| 46 |
+
original_graph = nx.Graph()
|
| 47 |
+
original_graph.add_nodes_from(n for n in nodes.items())
|
| 48 |
+
original_graph.add_edges_from((u, v, {"type": label}) for u, v, label in edges)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
plt.suptitle("SNAP Summarization")
|
| 52 |
+
|
| 53 |
+
base_options = dict(with_labels=True, edgecolors="black", node_size=500)
|
| 54 |
+
|
| 55 |
+
ax1 = plt.subplot(1, 2, 1)
|
| 56 |
+
plt.title(
|
| 57 |
+
"Original (%s nodes, %s edges)"
|
| 58 |
+
% (original_graph.number_of_nodes(), original_graph.number_of_edges())
|
| 59 |
+
)
|
| 60 |
+
pos = nx.spring_layout(original_graph, seed=7482934)
|
| 61 |
+
node_colors = [d["color"] for _, d in original_graph.nodes(data=True)]
|
| 62 |
+
|
| 63 |
+
edge_type_visual_weight_lookup = {"Weak": 1.0, "Strong": 3.0}
|
| 64 |
+
edge_weights = [
|
| 65 |
+
edge_type_visual_weight_lookup[d["type"]]
|
| 66 |
+
for _, _, d in original_graph.edges(data=True)
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
nx.draw_networkx(
|
| 70 |
+
original_graph, pos=pos, node_color=node_colors, width=edge_weights, **base_options
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
node_attributes = ("color",)
|
| 74 |
+
edge_attributes = ("type",)
|
| 75 |
+
summary_graph = nx.snap_aggregation(
|
| 76 |
+
original_graph, node_attributes, edge_attributes, prefix="S-"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
plt.subplot(1, 2, 2)
|
| 80 |
+
|
| 81 |
+
plt.title(
|
| 82 |
+
"SNAP Aggregation (%s nodes, %s edges)"
|
| 83 |
+
% (summary_graph.number_of_nodes(), summary_graph.number_of_edges())
|
| 84 |
+
)
|
| 85 |
+
summary_pos = nx.spring_layout(summary_graph, seed=8375428)
|
| 86 |
+
node_colors = []
|
| 87 |
+
for node in summary_graph:
|
| 88 |
+
color = summary_graph.nodes[node]["color"]
|
| 89 |
+
node_colors.append(color)
|
| 90 |
+
|
| 91 |
+
edge_weights = []
|
| 92 |
+
for edge in summary_graph.edges():
|
| 93 |
+
edge_types = summary_graph.get_edge_data(*edge)["types"]
|
| 94 |
+
edge_weight = 0.0
|
| 95 |
+
for edge_type in edge_types:
|
| 96 |
+
edge_weight += edge_type_visual_weight_lookup[edge_type["type"]]
|
| 97 |
+
edge_weights.append(edge_weight)
|
| 98 |
+
|
| 99 |
+
nx.draw_networkx(
|
| 100 |
+
summary_graph,
|
| 101 |
+
pos=summary_pos,
|
| 102 |
+
node_color=node_colors,
|
| 103 |
+
width=edge_weights,
|
| 104 |
+
**base_options
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
plt.tight_layout()
|
| 108 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Basic
|
| 2 |
+
-----
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_properties.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==========
|
| 3 |
+
Properties
|
| 4 |
+
==========
|
| 5 |
+
|
| 6 |
+
Compute some network properties for the lollipop graph.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.lollipop_graph(4, 6)
|
| 13 |
+
|
| 14 |
+
pathlengths = []
|
| 15 |
+
|
| 16 |
+
print("source vertex {target:length, }")
|
| 17 |
+
for v in G.nodes():
|
| 18 |
+
spl = dict(nx.single_source_shortest_path_length(G, v))
|
| 19 |
+
print(f"{v} {spl} ")
|
| 20 |
+
for p in spl:
|
| 21 |
+
pathlengths.append(spl[p])
|
| 22 |
+
|
| 23 |
+
print()
|
| 24 |
+
print(f"average shortest path length {sum(pathlengths) / len(pathlengths)}")
|
| 25 |
+
|
| 26 |
+
# histogram of path lengths
|
| 27 |
+
dist = {}
|
| 28 |
+
for p in pathlengths:
|
| 29 |
+
if p in dist:
|
| 30 |
+
dist[p] += 1
|
| 31 |
+
else:
|
| 32 |
+
dist[p] = 1
|
| 33 |
+
|
| 34 |
+
print()
|
| 35 |
+
print("length #paths")
|
| 36 |
+
verts = dist.keys()
|
| 37 |
+
for d in sorted(verts):
|
| 38 |
+
print(f"{d} {dist[d]}")
|
| 39 |
+
|
| 40 |
+
print(f"radius: {nx.radius(G)}")
|
| 41 |
+
print(f"diameter: {nx.diameter(G)}")
|
| 42 |
+
print(f"eccentricity: {nx.eccentricity(G)}")
|
| 43 |
+
print(f"center: {nx.center(G)}")
|
| 44 |
+
print(f"periphery: {nx.periphery(G)}")
|
| 45 |
+
print(f"density: {nx.density(G)}")
|
| 46 |
+
|
| 47 |
+
pos = nx.spring_layout(G, seed=3068) # Seed layout for reproducibility
|
| 48 |
+
nx.draw(G, pos=pos, with_labels=True)
|
| 49 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_read_write.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
======================
|
| 3 |
+
Read and write graphs.
|
| 4 |
+
======================
|
| 5 |
+
|
| 6 |
+
Read and write graphs.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.grid_2d_graph(5, 5) # 5x5 grid
|
| 13 |
+
|
| 14 |
+
# print the adjacency list
|
| 15 |
+
for line in nx.generate_adjlist(G):
|
| 16 |
+
print(line)
|
| 17 |
+
# write edgelist to grid.edgelist
|
| 18 |
+
nx.write_edgelist(G, path="grid.edgelist", delimiter=":")
|
| 19 |
+
# read edgelist from grid.edgelist
|
| 20 |
+
H = nx.read_edgelist(path="grid.edgelist", delimiter=":")
|
| 21 |
+
|
| 22 |
+
pos = nx.spring_layout(H, seed=200)
|
| 23 |
+
nx.draw(H, pos)
|
| 24 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/basic/plot_simple_graph.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
============
|
| 3 |
+
Simple graph
|
| 4 |
+
============
|
| 5 |
+
|
| 6 |
+
Draw simple graph with manual layout.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import networkx as nx
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
|
| 12 |
+
G = nx.Graph()
|
| 13 |
+
G.add_edge(1, 2)
|
| 14 |
+
G.add_edge(1, 3)
|
| 15 |
+
G.add_edge(1, 5)
|
| 16 |
+
G.add_edge(2, 3)
|
| 17 |
+
G.add_edge(3, 4)
|
| 18 |
+
G.add_edge(4, 5)
|
| 19 |
+
|
| 20 |
+
# explicitly set positions
|
| 21 |
+
pos = {1: (0, 0), 2: (-1, 0.3), 3: (2, 0.17), 4: (4, 0.255), 5: (5, 0.03)}
|
| 22 |
+
|
| 23 |
+
options = {
|
| 24 |
+
"font_size": 36,
|
| 25 |
+
"node_size": 3000,
|
| 26 |
+
"node_color": "white",
|
| 27 |
+
"edgecolors": "black",
|
| 28 |
+
"linewidths": 5,
|
| 29 |
+
"width": 5,
|
| 30 |
+
}
|
| 31 |
+
nx.draw_networkx(G, pos, **options)
|
| 32 |
+
|
| 33 |
+
# Set margins for the axes so that nodes aren't clipped
|
| 34 |
+
ax = plt.gca()
|
| 35 |
+
ax.margins(0.20)
|
| 36 |
+
plt.axis("off")
|
| 37 |
+
plt.show()
|
| 38 |
+
|
| 39 |
+
# %%
|
| 40 |
+
# A directed graph
|
| 41 |
+
|
| 42 |
+
G = nx.DiGraph([(0, 3), (1, 3), (2, 4), (3, 5), (3, 6), (4, 6), (5, 6)])
|
| 43 |
+
|
| 44 |
+
# group nodes by column
|
| 45 |
+
left_nodes = [0, 1, 2]
|
| 46 |
+
middle_nodes = [3, 4]
|
| 47 |
+
right_nodes = [5, 6]
|
| 48 |
+
|
| 49 |
+
# set the position according to column (x-coord)
|
| 50 |
+
pos = {n: (0, i) for i, n in enumerate(left_nodes)}
|
| 51 |
+
pos.update({n: (1, i + 0.5) for i, n in enumerate(middle_nodes)})
|
| 52 |
+
pos.update({n: (2, i + 0.5) for i, n in enumerate(right_nodes)})
|
| 53 |
+
|
| 54 |
+
nx.draw_networkx(G, pos, **options)
|
| 55 |
+
|
| 56 |
+
# Set margins for the axes so that nodes aren't clipped
|
| 57 |
+
ax = plt.gca()
|
| 58 |
+
ax.margins(0.20)
|
| 59 |
+
plt.axis("off")
|
| 60 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Drawing
|
| 2 |
+
-------
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_chess_masters.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=============
|
| 3 |
+
Chess Masters
|
| 4 |
+
=============
|
| 5 |
+
|
| 6 |
+
An example of the MultiDiGraph class.
|
| 7 |
+
|
| 8 |
+
The function `chess_pgn_graph` reads a collection of chess matches stored in
|
| 9 |
+
the specified PGN file (PGN ="Portable Game Notation"). Here the (compressed)
|
| 10 |
+
default file::
|
| 11 |
+
|
| 12 |
+
chess_masters_WCC.pgn.bz2
|
| 13 |
+
|
| 14 |
+
contains all 685 World Chess Championship matches from 1886--1985.
|
| 15 |
+
(data from http://chessproblem.my-free-games.com/chess/games/Download-PGN.php)
|
| 16 |
+
|
| 17 |
+
The `chess_pgn_graph()` function returns a `MultiDiGraph` with multiple edges.
|
| 18 |
+
Each node is the last name of a chess master. Each edge is directed from white
|
| 19 |
+
to black and contains selected game info.
|
| 20 |
+
|
| 21 |
+
The key statement in `chess_pgn_graph` below is::
|
| 22 |
+
|
| 23 |
+
G.add_edge(white, black, game_info)
|
| 24 |
+
|
| 25 |
+
where `game_info` is a `dict` describing each game.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
import matplotlib.pyplot as plt
|
| 29 |
+
import networkx as nx
|
| 30 |
+
|
| 31 |
+
# tag names specifying what game info should be
|
| 32 |
+
# stored in the dict on each digraph edge
|
| 33 |
+
game_details = ["Event", "Date", "Result", "ECO", "Site"]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def chess_pgn_graph(pgn_file="chess_masters_WCC.pgn.bz2"):
|
| 37 |
+
"""Read chess games in pgn format in pgn_file.
|
| 38 |
+
|
| 39 |
+
Filenames ending in .bz2 will be uncompressed.
|
| 40 |
+
|
| 41 |
+
Return the MultiDiGraph of players connected by a chess game.
|
| 42 |
+
Edges contain game data in a dict.
|
| 43 |
+
|
| 44 |
+
"""
|
| 45 |
+
import bz2
|
| 46 |
+
|
| 47 |
+
G = nx.MultiDiGraph()
|
| 48 |
+
game = {}
|
| 49 |
+
with bz2.BZ2File(pgn_file) as datafile:
|
| 50 |
+
lines = [line.decode().rstrip("\r\n") for line in datafile]
|
| 51 |
+
for line in lines:
|
| 52 |
+
if line.startswith("["):
|
| 53 |
+
tag, value = line[1:-1].split(" ", 1)
|
| 54 |
+
game[str(tag)] = value.strip('"')
|
| 55 |
+
else:
|
| 56 |
+
# empty line after tag set indicates
|
| 57 |
+
# we finished reading game info
|
| 58 |
+
if game:
|
| 59 |
+
white = game.pop("White")
|
| 60 |
+
black = game.pop("Black")
|
| 61 |
+
G.add_edge(white, black, **game)
|
| 62 |
+
game = {}
|
| 63 |
+
return G
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
G = chess_pgn_graph()
|
| 67 |
+
|
| 68 |
+
print(
|
| 69 |
+
f"Loaded {G.number_of_edges()} chess games between {G.number_of_nodes()} players\n"
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# identify connected components of the undirected version
|
| 73 |
+
H = G.to_undirected()
|
| 74 |
+
Gcc = [H.subgraph(c) for c in nx.connected_components(H)]
|
| 75 |
+
if len(Gcc) > 1:
|
| 76 |
+
print(f"Note the disconnected component consisting of:\n{Gcc[1].nodes()}")
|
| 77 |
+
|
| 78 |
+
# find all games with B97 opening (as described in ECO)
|
| 79 |
+
openings = {game_info["ECO"] for (white, black, game_info) in G.edges(data=True)}
|
| 80 |
+
print(f"\nFrom a total of {len(openings)} different openings,")
|
| 81 |
+
print("the following games used the Sicilian opening")
|
| 82 |
+
print('with the Najdorff 7...Qb6 "Poisoned Pawn" variation.\n')
|
| 83 |
+
|
| 84 |
+
for (white, black, game_info) in G.edges(data=True):
|
| 85 |
+
if game_info["ECO"] == "B97":
|
| 86 |
+
summary = f"{white} vs {black}\n"
|
| 87 |
+
for k, v in game_info.items():
|
| 88 |
+
summary += f" {k}: {v}\n"
|
| 89 |
+
summary += "\n"
|
| 90 |
+
print(summary)
|
| 91 |
+
|
| 92 |
+
# make new undirected graph H without multi-edges
|
| 93 |
+
H = nx.Graph(G)
|
| 94 |
+
|
| 95 |
+
# edge width is proportional number of games played
|
| 96 |
+
edgewidth = [len(G.get_edge_data(u, v)) for u, v in H.edges()]
|
| 97 |
+
|
| 98 |
+
# node size is proportional to number of games won
|
| 99 |
+
wins = dict.fromkeys(G.nodes(), 0.0)
|
| 100 |
+
for (u, v, d) in G.edges(data=True):
|
| 101 |
+
r = d["Result"].split("-")
|
| 102 |
+
if r[0] == "1":
|
| 103 |
+
wins[u] += 1.0
|
| 104 |
+
elif r[0] == "1/2":
|
| 105 |
+
wins[u] += 0.5
|
| 106 |
+
wins[v] += 0.5
|
| 107 |
+
else:
|
| 108 |
+
wins[v] += 1.0
|
| 109 |
+
nodesize = [wins[v] * 50 for v in H]
|
| 110 |
+
|
| 111 |
+
# Generate layout for visualization
|
| 112 |
+
pos = nx.kamada_kawai_layout(H)
|
| 113 |
+
# Manual tweaking to limit node label overlap in the visualization
|
| 114 |
+
pos["Reshevsky, Samuel H"] += (0.05, -0.10)
|
| 115 |
+
pos["Botvinnik, Mikhail M"] += (0.03, -0.06)
|
| 116 |
+
pos["Smyslov, Vassily V"] += (0.05, -0.03)
|
| 117 |
+
|
| 118 |
+
fig, ax = plt.subplots(figsize=(12, 12))
|
| 119 |
+
# Visualize graph components
|
| 120 |
+
nx.draw_networkx_edges(H, pos, alpha=0.3, width=edgewidth, edge_color="m")
|
| 121 |
+
nx.draw_networkx_nodes(H, pos, node_size=nodesize, node_color="#210070", alpha=0.9)
|
| 122 |
+
label_options = {"ec": "k", "fc": "white", "alpha": 0.7}
|
| 123 |
+
nx.draw_networkx_labels(H, pos, font_size=14, bbox=label_options)
|
| 124 |
+
|
| 125 |
+
# Title/legend
|
| 126 |
+
font = {"fontname": "Helvetica", "color": "k", "fontweight": "bold", "fontsize": 14}
|
| 127 |
+
ax.set_title("World Chess Championship Games: 1886 - 1985", font)
|
| 128 |
+
# Change font color for legend
|
| 129 |
+
font["color"] = "r"
|
| 130 |
+
|
| 131 |
+
ax.text(
|
| 132 |
+
0.80,
|
| 133 |
+
0.10,
|
| 134 |
+
"edge width = # games played",
|
| 135 |
+
horizontalalignment="center",
|
| 136 |
+
transform=ax.transAxes,
|
| 137 |
+
fontdict=font,
|
| 138 |
+
)
|
| 139 |
+
ax.text(
|
| 140 |
+
0.80,
|
| 141 |
+
0.06,
|
| 142 |
+
"node size = # games won",
|
| 143 |
+
horizontalalignment="center",
|
| 144 |
+
transform=ax.transAxes,
|
| 145 |
+
fontdict=font,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# Resize figure for label readibility
|
| 149 |
+
ax.margins(0.1, 0.05)
|
| 150 |
+
fig.tight_layout()
|
| 151 |
+
plt.axis("off")
|
| 152 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_custom_node_icons.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=================
|
| 3 |
+
Custom node icons
|
| 4 |
+
=================
|
| 5 |
+
|
| 6 |
+
Example of using custom icons to represent nodes with matplotlib.
|
| 7 |
+
|
| 8 |
+
Images for node icons courtesy of www.materialui.co
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import matplotlib.pyplot as plt
|
| 12 |
+
import networkx as nx
|
| 13 |
+
import PIL
|
| 14 |
+
|
| 15 |
+
# Image URLs for graph nodes
|
| 16 |
+
icons = {
|
| 17 |
+
"router": "icons/router_black_144x144.png",
|
| 18 |
+
"switch": "icons/switch_black_144x144.png",
|
| 19 |
+
"PC": "icons/computer_black_144x144.png",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
# Load images
|
| 23 |
+
images = {k: PIL.Image.open(fname) for k, fname in icons.items()}
|
| 24 |
+
|
| 25 |
+
# Generate the computer network graph
|
| 26 |
+
G = nx.Graph()
|
| 27 |
+
|
| 28 |
+
G.add_node("router", image=images["router"])
|
| 29 |
+
for i in range(1, 4):
|
| 30 |
+
G.add_node(f"switch_{i}", image=images["switch"])
|
| 31 |
+
for j in range(1, 4):
|
| 32 |
+
G.add_node("PC_" + str(i) + "_" + str(j), image=images["PC"])
|
| 33 |
+
|
| 34 |
+
G.add_edge("router", "switch_1")
|
| 35 |
+
G.add_edge("router", "switch_2")
|
| 36 |
+
G.add_edge("router", "switch_3")
|
| 37 |
+
for u in range(1, 4):
|
| 38 |
+
for v in range(1, 4):
|
| 39 |
+
G.add_edge("switch_" + str(u), "PC_" + str(u) + "_" + str(v))
|
| 40 |
+
|
| 41 |
+
# Get a reproducible layout and create figure
|
| 42 |
+
pos = nx.spring_layout(G, seed=1734289230)
|
| 43 |
+
fig, ax = plt.subplots()
|
| 44 |
+
|
| 45 |
+
# Note: the min_source/target_margin kwargs only work with FancyArrowPatch objects.
|
| 46 |
+
# Force the use of FancyArrowPatch for edge drawing by setting `arrows=True`,
|
| 47 |
+
# but suppress arrowheads with `arrowstyle="-"`
|
| 48 |
+
nx.draw_networkx_edges(
|
| 49 |
+
G,
|
| 50 |
+
pos=pos,
|
| 51 |
+
ax=ax,
|
| 52 |
+
arrows=True,
|
| 53 |
+
arrowstyle="-",
|
| 54 |
+
min_source_margin=15,
|
| 55 |
+
min_target_margin=15,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Transform from data coordinates (scaled between xlim and ylim) to display coordinates
|
| 59 |
+
tr_figure = ax.transData.transform
|
| 60 |
+
# Transform from display to figure coordinates
|
| 61 |
+
tr_axes = fig.transFigure.inverted().transform
|
| 62 |
+
|
| 63 |
+
# Select the size of the image (relative to the X axis)
|
| 64 |
+
icon_size = (ax.get_xlim()[1] - ax.get_xlim()[0]) * 0.025
|
| 65 |
+
icon_center = icon_size / 2.0
|
| 66 |
+
|
| 67 |
+
# Add the respective image to each node
|
| 68 |
+
for n in G.nodes:
|
| 69 |
+
xf, yf = tr_figure(pos[n])
|
| 70 |
+
xa, ya = tr_axes((xf, yf))
|
| 71 |
+
# get overlapped axes and plot icon
|
| 72 |
+
a = plt.axes([xa - icon_center, ya - icon_center, icon_size, icon_size])
|
| 73 |
+
a.imshow(G.nodes[n]["image"])
|
| 74 |
+
a.axis("off")
|
| 75 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_degree.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===============
|
| 3 |
+
Degree Analysis
|
| 4 |
+
===============
|
| 5 |
+
|
| 6 |
+
This example shows several ways to visualize the distribution of the degree of
|
| 7 |
+
nodes with two common techniques: a *degree-rank plot* and a
|
| 8 |
+
*degree histogram*.
|
| 9 |
+
|
| 10 |
+
In this example, a random Graph is generated with 100 nodes. The degree of
|
| 11 |
+
each node is determined, and a figure is generated showing three things:
|
| 12 |
+
1. The subgraph of connected components
|
| 13 |
+
2. The degree-rank plot for the Graph, and
|
| 14 |
+
3. The degree histogram
|
| 15 |
+
"""
|
| 16 |
+
import networkx as nx
|
| 17 |
+
import numpy as np
|
| 18 |
+
import matplotlib.pyplot as plt
|
| 19 |
+
|
| 20 |
+
G = nx.gnp_random_graph(100, 0.02, seed=10374196)
|
| 21 |
+
|
| 22 |
+
degree_sequence = sorted([d for n, d in G.degree()], reverse=True)
|
| 23 |
+
dmax = max(degree_sequence)
|
| 24 |
+
|
| 25 |
+
fig = plt.figure("Degree of a random graph", figsize=(8, 8))
|
| 26 |
+
# Create a gridspec for adding subplots of different sizes
|
| 27 |
+
axgrid = fig.add_gridspec(5, 4)
|
| 28 |
+
|
| 29 |
+
ax0 = fig.add_subplot(axgrid[0:3, :])
|
| 30 |
+
Gcc = G.subgraph(sorted(nx.connected_components(G), key=len, reverse=True)[0])
|
| 31 |
+
pos = nx.spring_layout(Gcc, seed=10396953)
|
| 32 |
+
nx.draw_networkx_nodes(Gcc, pos, ax=ax0, node_size=20)
|
| 33 |
+
nx.draw_networkx_edges(Gcc, pos, ax=ax0, alpha=0.4)
|
| 34 |
+
ax0.set_title("Connected components of G")
|
| 35 |
+
ax0.set_axis_off()
|
| 36 |
+
|
| 37 |
+
ax1 = fig.add_subplot(axgrid[3:, :2])
|
| 38 |
+
ax1.plot(degree_sequence, "b-", marker="o")
|
| 39 |
+
ax1.set_title("Degree Rank Plot")
|
| 40 |
+
ax1.set_ylabel("Degree")
|
| 41 |
+
ax1.set_xlabel("Rank")
|
| 42 |
+
|
| 43 |
+
ax2 = fig.add_subplot(axgrid[3:, 2:])
|
| 44 |
+
ax2.bar(*np.unique(degree_sequence, return_counts=True))
|
| 45 |
+
ax2.set_title("Degree histogram")
|
| 46 |
+
ax2.set_xlabel("Degree")
|
| 47 |
+
ax2.set_ylabel("# of Nodes")
|
| 48 |
+
|
| 49 |
+
fig.tight_layout()
|
| 50 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_directed.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==============
|
| 3 |
+
Directed Graph
|
| 4 |
+
==============
|
| 5 |
+
|
| 6 |
+
Draw a graph with directed edges using a colormap and different node sizes.
|
| 7 |
+
|
| 8 |
+
Edges have different colors and alphas (opacity). Drawn using matplotlib.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import matplotlib as mpl
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
import networkx as nx
|
| 14 |
+
|
| 15 |
+
seed = 13648 # Seed random number generators for reproducibility
|
| 16 |
+
G = nx.random_k_out_graph(10, 3, 0.5, seed=seed)
|
| 17 |
+
pos = nx.spring_layout(G, seed=seed)
|
| 18 |
+
|
| 19 |
+
node_sizes = [3 + 10 * i for i in range(len(G))]
|
| 20 |
+
M = G.number_of_edges()
|
| 21 |
+
edge_colors = range(2, M + 2)
|
| 22 |
+
edge_alphas = [(5 + i) / (M + 4) for i in range(M)]
|
| 23 |
+
cmap = plt.cm.plasma
|
| 24 |
+
|
| 25 |
+
nodes = nx.draw_networkx_nodes(G, pos, node_size=node_sizes, node_color="indigo")
|
| 26 |
+
edges = nx.draw_networkx_edges(
|
| 27 |
+
G,
|
| 28 |
+
pos,
|
| 29 |
+
node_size=node_sizes,
|
| 30 |
+
arrowstyle="->",
|
| 31 |
+
arrowsize=10,
|
| 32 |
+
edge_color=edge_colors,
|
| 33 |
+
edge_cmap=cmap,
|
| 34 |
+
width=2,
|
| 35 |
+
)
|
| 36 |
+
# set alpha value for each edge
|
| 37 |
+
for i in range(M):
|
| 38 |
+
edges[i].set_alpha(edge_alphas[i])
|
| 39 |
+
|
| 40 |
+
pc = mpl.collections.PatchCollection(edges, cmap=cmap)
|
| 41 |
+
pc.set_array(edge_colors)
|
| 42 |
+
plt.colorbar(pc)
|
| 43 |
+
|
| 44 |
+
ax = plt.gca()
|
| 45 |
+
ax.set_axis_off()
|
| 46 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_edge_colormap.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=============
|
| 3 |
+
Edge Colormap
|
| 4 |
+
=============
|
| 5 |
+
|
| 6 |
+
Draw a graph with matplotlib, color edges.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.star_graph(20)
|
| 13 |
+
pos = nx.spring_layout(G, seed=63) # Seed layout for reproducibility
|
| 14 |
+
colors = range(20)
|
| 15 |
+
options = {
|
| 16 |
+
"node_color": "#A0CBE2",
|
| 17 |
+
"edge_color": colors,
|
| 18 |
+
"width": 4,
|
| 19 |
+
"edge_cmap": plt.cm.Blues,
|
| 20 |
+
"with_labels": False,
|
| 21 |
+
}
|
| 22 |
+
nx.draw(G, pos, **options)
|
| 23 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_ego_graph.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=========
|
| 3 |
+
Ego Graph
|
| 4 |
+
=========
|
| 5 |
+
|
| 6 |
+
Example using the NetworkX ego_graph() function to return the main egonet of
|
| 7 |
+
the largest hub in a Barabási-Albert network.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from operator import itemgetter
|
| 11 |
+
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
import networkx as nx
|
| 14 |
+
|
| 15 |
+
# Create a BA model graph - use seed for reproducibility
|
| 16 |
+
n = 1000
|
| 17 |
+
m = 2
|
| 18 |
+
seed = 20532
|
| 19 |
+
G = nx.barabasi_albert_graph(n, m, seed=seed)
|
| 20 |
+
|
| 21 |
+
# find node with largest degree
|
| 22 |
+
node_and_degree = G.degree()
|
| 23 |
+
(largest_hub, degree) = sorted(node_and_degree, key=itemgetter(1))[-1]
|
| 24 |
+
|
| 25 |
+
# Create ego graph of main hub
|
| 26 |
+
hub_ego = nx.ego_graph(G, largest_hub)
|
| 27 |
+
|
| 28 |
+
# Draw graph
|
| 29 |
+
pos = nx.spring_layout(hub_ego, seed=seed) # Seed layout for reproducibility
|
| 30 |
+
nx.draw(hub_ego, pos, node_color="b", node_size=50, with_labels=False)
|
| 31 |
+
|
| 32 |
+
# Draw ego as large and red
|
| 33 |
+
options = {"node_size": 300, "node_color": "r"}
|
| 34 |
+
nx.draw_networkx_nodes(hub_ego, pos, nodelist=[largest_hub], **options)
|
| 35 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_eigenvalues.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===========
|
| 3 |
+
Eigenvalues
|
| 4 |
+
===========
|
| 5 |
+
|
| 6 |
+
Create an G{n,m} random graph and compute the eigenvalues.
|
| 7 |
+
"""
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import networkx as nx
|
| 10 |
+
import numpy.linalg
|
| 11 |
+
|
| 12 |
+
n = 1000 # 1000 nodes
|
| 13 |
+
m = 5000 # 5000 edges
|
| 14 |
+
G = nx.gnm_random_graph(n, m, seed=5040) # Seed for reproducibility
|
| 15 |
+
|
| 16 |
+
L = nx.normalized_laplacian_matrix(G)
|
| 17 |
+
e = numpy.linalg.eigvals(L.A)
|
| 18 |
+
print("Largest eigenvalue:", max(e))
|
| 19 |
+
print("Smallest eigenvalue:", min(e))
|
| 20 |
+
plt.hist(e, bins=100) # histogram with 100 bins
|
| 21 |
+
plt.xlim(0, 2) # eigenvalues between 0 and 2
|
| 22 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_four_grids.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
==========
|
| 3 |
+
Four Grids
|
| 4 |
+
==========
|
| 5 |
+
|
| 6 |
+
Draw a 4x4 graph with matplotlib.
|
| 7 |
+
|
| 8 |
+
This example illustrates the use of keyword arguments to `networkx.draw` to
|
| 9 |
+
customize the visualization of a simple Graph comprising a 4x4 grid.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
import networkx as nx
|
| 14 |
+
|
| 15 |
+
G = nx.grid_2d_graph(4, 4) # 4x4 grid
|
| 16 |
+
|
| 17 |
+
pos = nx.spring_layout(G, iterations=100, seed=39775)
|
| 18 |
+
|
| 19 |
+
# Create a 2x2 subplot
|
| 20 |
+
fig, all_axes = plt.subplots(2, 2)
|
| 21 |
+
ax = all_axes.flat
|
| 22 |
+
|
| 23 |
+
nx.draw(G, pos, ax=ax[0], font_size=8)
|
| 24 |
+
nx.draw(G, pos, ax=ax[1], node_size=0, with_labels=False)
|
| 25 |
+
nx.draw(
|
| 26 |
+
G,
|
| 27 |
+
pos,
|
| 28 |
+
ax=ax[2],
|
| 29 |
+
node_color="tab:green",
|
| 30 |
+
edgecolors="tab:gray", # Node surface color
|
| 31 |
+
edge_color="tab:gray", # Color of graph edges
|
| 32 |
+
node_size=250,
|
| 33 |
+
with_labels=False,
|
| 34 |
+
width=6,
|
| 35 |
+
)
|
| 36 |
+
H = G.to_directed()
|
| 37 |
+
nx.draw(
|
| 38 |
+
H,
|
| 39 |
+
pos,
|
| 40 |
+
ax=ax[3],
|
| 41 |
+
node_color="tab:orange",
|
| 42 |
+
node_size=20,
|
| 43 |
+
with_labels=False,
|
| 44 |
+
arrowsize=10,
|
| 45 |
+
width=2,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Set margins for the axes so that nodes aren't clipped
|
| 49 |
+
for a in ax:
|
| 50 |
+
a.margins(0.10)
|
| 51 |
+
fig.tight_layout()
|
| 52 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_house_with_colors.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=================
|
| 3 |
+
House With Colors
|
| 4 |
+
=================
|
| 5 |
+
|
| 6 |
+
Draw a graph with matplotlib.
|
| 7 |
+
"""
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import networkx as nx
|
| 10 |
+
|
| 11 |
+
G = nx.house_graph()
|
| 12 |
+
# explicitly set positions
|
| 13 |
+
pos = {0: (0, 0), 1: (1, 0), 2: (0, 1), 3: (1, 1), 4: (0.5, 2.0)}
|
| 14 |
+
|
| 15 |
+
# Plot nodes with different properties for the "wall" and "roof" nodes
|
| 16 |
+
nx.draw_networkx_nodes(
|
| 17 |
+
G, pos, node_size=3000, nodelist=[0, 1, 2, 3], node_color="tab:blue"
|
| 18 |
+
)
|
| 19 |
+
nx.draw_networkx_nodes(G, pos, node_size=2000, nodelist=[4], node_color="tab:orange")
|
| 20 |
+
nx.draw_networkx_edges(G, pos, alpha=0.5, width=6)
|
| 21 |
+
# Customize axes
|
| 22 |
+
ax = plt.gca()
|
| 23 |
+
ax.margins(0.11)
|
| 24 |
+
plt.tight_layout()
|
| 25 |
+
plt.axis("off")
|
| 26 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_knuth_miles.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===========
|
| 3 |
+
Knuth Miles
|
| 4 |
+
===========
|
| 5 |
+
|
| 6 |
+
`miles_graph()` returns an undirected graph over 128 US cities. The
|
| 7 |
+
cities each have location and population data. The edges are labeled with the
|
| 8 |
+
distance between the two cities.
|
| 9 |
+
|
| 10 |
+
This example is described in Section 1.1 of
|
| 11 |
+
|
| 12 |
+
Donald E. Knuth, "The Stanford GraphBase: A Platform for Combinatorial
|
| 13 |
+
Computing", ACM Press, New York, 1993.
|
| 14 |
+
http://www-cs-faculty.stanford.edu/~knuth/sgb.html
|
| 15 |
+
|
| 16 |
+
The data file can be found at:
|
| 17 |
+
|
| 18 |
+
- https://github.com/networkx/networkx/blob/main/examples/drawing/knuth_miles.txt.gz
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import gzip
|
| 22 |
+
import re
|
| 23 |
+
|
| 24 |
+
# Ignore any warnings related to downloading shpfiles with cartopy
|
| 25 |
+
import warnings
|
| 26 |
+
|
| 27 |
+
warnings.simplefilter("ignore")
|
| 28 |
+
|
| 29 |
+
import numpy as np
|
| 30 |
+
import matplotlib.pyplot as plt
|
| 31 |
+
import networkx as nx
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def miles_graph():
|
| 35 |
+
"""Return the cites example graph in miles_dat.txt
|
| 36 |
+
from the Stanford GraphBase.
|
| 37 |
+
"""
|
| 38 |
+
# open file miles_dat.txt.gz (or miles_dat.txt)
|
| 39 |
+
|
| 40 |
+
fh = gzip.open("knuth_miles.txt.gz", "r")
|
| 41 |
+
|
| 42 |
+
G = nx.Graph()
|
| 43 |
+
G.position = {}
|
| 44 |
+
G.population = {}
|
| 45 |
+
|
| 46 |
+
cities = []
|
| 47 |
+
for line in fh.readlines():
|
| 48 |
+
line = line.decode()
|
| 49 |
+
if line.startswith("*"): # skip comments
|
| 50 |
+
continue
|
| 51 |
+
|
| 52 |
+
numfind = re.compile(r"^\d+")
|
| 53 |
+
|
| 54 |
+
if numfind.match(line): # this line is distances
|
| 55 |
+
dist = line.split()
|
| 56 |
+
for d in dist:
|
| 57 |
+
G.add_edge(city, cities[i], weight=int(d))
|
| 58 |
+
i = i + 1
|
| 59 |
+
else: # this line is a city, position, population
|
| 60 |
+
i = 1
|
| 61 |
+
(city, coordpop) = line.split("[")
|
| 62 |
+
cities.insert(0, city)
|
| 63 |
+
(coord, pop) = coordpop.split("]")
|
| 64 |
+
(y, x) = coord.split(",")
|
| 65 |
+
|
| 66 |
+
G.add_node(city)
|
| 67 |
+
# assign position - Convert string to lat/long
|
| 68 |
+
G.position[city] = (-float(x) / 100, float(y) / 100)
|
| 69 |
+
G.population[city] = float(pop) / 1000.0
|
| 70 |
+
return G
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
G = miles_graph()
|
| 74 |
+
|
| 75 |
+
print("Loaded miles_dat.txt containing 128 cities.")
|
| 76 |
+
print(G)
|
| 77 |
+
|
| 78 |
+
# make new graph of cites, edge if less then 300 miles between them
|
| 79 |
+
H = nx.Graph()
|
| 80 |
+
for v in G:
|
| 81 |
+
H.add_node(v)
|
| 82 |
+
for (u, v, d) in G.edges(data=True):
|
| 83 |
+
if d["weight"] < 300:
|
| 84 |
+
H.add_edge(u, v)
|
| 85 |
+
|
| 86 |
+
# draw with matplotlib/pylab
|
| 87 |
+
fig = plt.figure(figsize=(8, 6))
|
| 88 |
+
|
| 89 |
+
# nodes colored by degree sized by population
|
| 90 |
+
node_color = [float(H.degree(v)) for v in H]
|
| 91 |
+
|
| 92 |
+
# Use cartopy to provide a backdrop for the visualization
|
| 93 |
+
try:
|
| 94 |
+
import cartopy.crs as ccrs
|
| 95 |
+
import cartopy.io.shapereader as shpreader
|
| 96 |
+
|
| 97 |
+
ax = fig.add_axes([0, 0, 1, 1], projection=ccrs.LambertConformal(), frameon=False)
|
| 98 |
+
ax.set_extent([-125, -66.5, 20, 50], ccrs.Geodetic())
|
| 99 |
+
# Add map of countries & US states as a backdrop
|
| 100 |
+
for shapename in ("admin_1_states_provinces_lakes_shp", "admin_0_countries"):
|
| 101 |
+
shp = shpreader.natural_earth(
|
| 102 |
+
resolution="110m", category="cultural", name=shapename
|
| 103 |
+
)
|
| 104 |
+
ax.add_geometries(
|
| 105 |
+
shpreader.Reader(shp).geometries(),
|
| 106 |
+
ccrs.PlateCarree(),
|
| 107 |
+
facecolor="none",
|
| 108 |
+
edgecolor="k",
|
| 109 |
+
)
|
| 110 |
+
# NOTE: When using cartopy, use matplotlib directly rather than nx.draw
|
| 111 |
+
# to take advantage of the cartopy transforms
|
| 112 |
+
ax.scatter(
|
| 113 |
+
*np.array([v for v in G.position.values()]).T,
|
| 114 |
+
s=[G.population[v] for v in H],
|
| 115 |
+
c=node_color,
|
| 116 |
+
transform=ccrs.PlateCarree(),
|
| 117 |
+
zorder=100 # Ensure nodes lie on top of edges/state lines
|
| 118 |
+
)
|
| 119 |
+
# Plot edges between the cities
|
| 120 |
+
for edge in H.edges():
|
| 121 |
+
edge_coords = np.array([G.position[v] for v in edge])
|
| 122 |
+
ax.plot(
|
| 123 |
+
edge_coords[:, 0],
|
| 124 |
+
edge_coords[:, 1],
|
| 125 |
+
transform=ccrs.PlateCarree(),
|
| 126 |
+
linewidth=0.75,
|
| 127 |
+
color="k",
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
except ImportError:
|
| 131 |
+
# If cartopy is unavailable, the backdrop for the plot will be blank;
|
| 132 |
+
# though you should still be able to discern the general shape of the US
|
| 133 |
+
# from graph nodes and edges!
|
| 134 |
+
nx.draw(
|
| 135 |
+
H,
|
| 136 |
+
G.position,
|
| 137 |
+
node_size=[G.population[v] for v in H],
|
| 138 |
+
node_color=node_color,
|
| 139 |
+
with_labels=False,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_labels_and_colors.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=================
|
| 3 |
+
Labels And Colors
|
| 4 |
+
=================
|
| 5 |
+
|
| 6 |
+
Use `nodelist` and `edgelist` to apply custom coloring and labels to various
|
| 7 |
+
components of a graph.
|
| 8 |
+
"""
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.cubical_graph()
|
| 13 |
+
pos = nx.spring_layout(G, seed=3113794652) # positions for all nodes
|
| 14 |
+
|
| 15 |
+
# nodes
|
| 16 |
+
options = {"edgecolors": "tab:gray", "node_size": 800, "alpha": 0.9}
|
| 17 |
+
nx.draw_networkx_nodes(G, pos, nodelist=[0, 1, 2, 3], node_color="tab:red", **options)
|
| 18 |
+
nx.draw_networkx_nodes(G, pos, nodelist=[4, 5, 6, 7], node_color="tab:blue", **options)
|
| 19 |
+
|
| 20 |
+
# edges
|
| 21 |
+
nx.draw_networkx_edges(G, pos, width=1.0, alpha=0.5)
|
| 22 |
+
nx.draw_networkx_edges(
|
| 23 |
+
G,
|
| 24 |
+
pos,
|
| 25 |
+
edgelist=[(0, 1), (1, 2), (2, 3), (3, 0)],
|
| 26 |
+
width=8,
|
| 27 |
+
alpha=0.5,
|
| 28 |
+
edge_color="tab:red",
|
| 29 |
+
)
|
| 30 |
+
nx.draw_networkx_edges(
|
| 31 |
+
G,
|
| 32 |
+
pos,
|
| 33 |
+
edgelist=[(4, 5), (5, 6), (6, 7), (7, 4)],
|
| 34 |
+
width=8,
|
| 35 |
+
alpha=0.5,
|
| 36 |
+
edge_color="tab:blue",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# some math labels
|
| 41 |
+
labels = {}
|
| 42 |
+
labels[0] = r"$a$"
|
| 43 |
+
labels[1] = r"$b$"
|
| 44 |
+
labels[2] = r"$c$"
|
| 45 |
+
labels[3] = r"$d$"
|
| 46 |
+
labels[4] = r"$\alpha$"
|
| 47 |
+
labels[5] = r"$\beta$"
|
| 48 |
+
labels[6] = r"$\gamma$"
|
| 49 |
+
labels[7] = r"$\delta$"
|
| 50 |
+
nx.draw_networkx_labels(G, pos, labels, font_size=22, font_color="whitesmoke")
|
| 51 |
+
|
| 52 |
+
plt.tight_layout()
|
| 53 |
+
plt.axis("off")
|
| 54 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_multipartite_graph.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
===================
|
| 3 |
+
Multipartite Layout
|
| 4 |
+
===================
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import itertools
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import networkx as nx
|
| 10 |
+
|
| 11 |
+
subset_sizes = [5, 5, 4, 3, 2, 4, 4, 3]
|
| 12 |
+
subset_color = [
|
| 13 |
+
"gold",
|
| 14 |
+
"violet",
|
| 15 |
+
"violet",
|
| 16 |
+
"violet",
|
| 17 |
+
"violet",
|
| 18 |
+
"limegreen",
|
| 19 |
+
"limegreen",
|
| 20 |
+
"darkorange",
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def multilayered_graph(*subset_sizes):
|
| 25 |
+
extents = nx.utils.pairwise(itertools.accumulate((0,) + subset_sizes))
|
| 26 |
+
layers = [range(start, end) for start, end in extents]
|
| 27 |
+
G = nx.Graph()
|
| 28 |
+
for (i, layer) in enumerate(layers):
|
| 29 |
+
G.add_nodes_from(layer, layer=i)
|
| 30 |
+
for layer1, layer2 in nx.utils.pairwise(layers):
|
| 31 |
+
G.add_edges_from(itertools.product(layer1, layer2))
|
| 32 |
+
return G
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
G = multilayered_graph(*subset_sizes)
|
| 36 |
+
color = [subset_color[data["layer"]] for v, data in G.nodes(data=True)]
|
| 37 |
+
pos = nx.multipartite_layout(G, subset_key="layer")
|
| 38 |
+
plt.figure(figsize=(8, 8))
|
| 39 |
+
nx.draw(G, pos, node_color=color, with_labels=False)
|
| 40 |
+
plt.axis("equal")
|
| 41 |
+
plt.show()
|
spiderfoot/venv-spiderfoot/share/doc/networkx-2.6.3/examples/drawing/plot_node_colormap.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
=============
|
| 3 |
+
Node Colormap
|
| 4 |
+
=============
|
| 5 |
+
|
| 6 |
+
Draw a graph with matplotlib, color by degree.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import matplotlib.pyplot as plt
|
| 10 |
+
import networkx as nx
|
| 11 |
+
|
| 12 |
+
G = nx.cycle_graph(24)
|
| 13 |
+
pos = nx.circular_layout(G)
|
| 14 |
+
nx.draw(G, pos, node_color=range(24), node_size=800, cmap=plt.cm.Blues)
|
| 15 |
+
plt.show()
|