Add locate IP script
This commit is contained in:
		
							parent
							
								
									6a2afb3280
								
							
						
					
					
						commit
						dc63263d85
					
				
					 1 changed files with 29 additions and 0 deletions
				
			
		
							
								
								
									
										29
									
								
								config/scripts/lip
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										29
									
								
								config/scripts/lip
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,29 @@ | ||||||
|  | #!/usr/bin/env sh | ||||||
|  | 
 | ||||||
|  | set -euo pipefail | ||||||
|  | 
 | ||||||
|  | url="https://ip.frogeye.fr/json" | ||||||
|  | cachedir="$HOME/.cache/lip" | ||||||
|  | 
 | ||||||
|  | ip="${1:-}" | ||||||
|  | if [ $# -gt 0 ] | ||||||
|  | then | ||||||
|  |     shift | ||||||
|  |     jq_sel="$@" | ||||||
|  | else | ||||||
|  |     jq_sel="del(.user_agent)" | ||||||
|  | fi | ||||||
|  | 
 | ||||||
|  | if [ -n "$ip" ] | ||||||
|  | then | ||||||
|  |     cachefile="$cachedir/$ip" | ||||||
|  |     if ! find "$cachefile" -mtime -7 &> /dev/null | ||||||
|  |     then | ||||||
|  |         mkdir -p "$cachedir" | ||||||
|  |         curl --silent "$url/?ip=$ip" > "$cachefile" | ||||||
|  |     fi | ||||||
|  |     cat "$cachefile" | jq $jq_sel | ||||||
|  | else | ||||||
|  |     curl --silent "$url" | jq $jq_sel | ||||||
|  | fi | ||||||
|  | 
 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue