; IPFindGoogleMap.ahk ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: Jack Dunning (https://jacksautohotkeyblog.wordpress.com/about/contact-jack/) ; ; Script Function: (Maps non-functional. Script included for reference only. See the IPFindOpenStreetMap.ahk script.) ; Find IP addresses in selected text and access the Web for geographic location. Hotkey CTRL+ALT+I ; ; March 3, 2019, Rewrote the script to use a more reliable Web page with better information. ; April 23, 2021, Fixed for changed Web page formatting. Added list to map. Converted to GUI. ; May 6, 2021, Switched to new source page since blocked by old source. ; May 10, 2021, Added maps from OpenStreetMap.com to GUI ; May 20, 2021, Switched to iFrame with embedded Google Map ; May 30, 2021, Google blocked iFrame map embedding. Switched to OpenStreetMap.org. ; See the script IPFindOpenStreetMap.ahk for up-to-date script. ; The following next Regular Expression is for complete validation within range of 0-255 ; ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ; Reduced RegEx for a match only ; \b(\d{1,3}\.){3}\d{1,3}\b ; Windows Registry change for IE compatibility with AutoHotkey ; Discussed in https://jacks-autohotkey-blog.com/2021/05/17/embed-google-maps-in-an-autohotkey-gui-no-api-required/ ;RegRead,KeyValue,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION,AutoHotkey.exe ;If ErrorLevel RegWrite, REG_DWORD,HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION,AutoHotkey.exe,11001 HTML1 := "
" ; MsgBox %HTML1%[lat,long]%HTML2% Return ^!i:: OldClipboard:= ClipboardAll Clipboard:= "" Send, ^c ;copies selected text ClipWait 0 If ErrorLevel { MsgBox, No Text Selected! Return } CountIP := 1 Next := 1 Loop { FoundPos := RegExMatch(Clipboard, "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b" , ipaddress%CountIP%, Next) Next := FoundPos + StrLen(ipaddress%CountIP%) If FoundPos = 0 Break CountIP++ } Gui, +AlwaysOnTop If IPAddress1 { CountIP-- Loop, %CountIP% { CheckIP := ipaddress%A_Index% WhereIs := GetLocation(CheckIP) ; For city, state, country map RegExMatch(WhereIs[1], "City(.*?)Region", City) RegExMatch(WhereIs[1], "Region(.*?)\s\(", State) RegExMatch(WhereIs[1], "Country(.*?)\s\(", Country) ; MapEmbed := HTML1 . City1 . "," . State1 . "," Country1 . HTML2 ; For latitude, longitude map MapEmbed := HTML1 . WhereIs[2] . HTML2 FileDelete, %A_ScriptDir%\GoogleMapEmbed.html FileAppend , %MapEmbed%, %A_ScriptDir%\GoogleMapEmbed.html ; msgbox % WhereIs[1] "`r" City "`r" City1 "`r" State "`r" State1 "`r" Country "`r" country1 WhereIs[1] := StrReplace(WhereIs[1],"Postal code","`rPostal code:`t") WhereIs[1] := StrReplace(WhereIs[1],"Region","`rRegion/State:") WhereIs[1] := StrReplace(WhereIs[1],"Country","`rCountry:`t`t") WhereIs[1] := StrReplace(WhereIs[1],"State:","State:`t") WhereIs[1] := StrReplace(WhereIs[1],"Continent","`rContinent:`t") WhereIs[1] := StrReplace(WhereIs[1],"Metro code","`rMetro code:`t") WhereIs[1] := StrReplace(WhereIs[1],"City","`rCity:`t`t") WhereIs[1] := StrReplace(WhereIs[1],"Coordinates","`rCordinates:`t") Gui, Add , Text, xm section, % CheckIP . WhereIs[1] Gui Add, ActiveX, ys x250 w200 h200 vWB%A_Index%, Shell.Explorer FilePathName := A_ScriptDir . "\GoogleMapEmbed.html" WB%A_Index%.Navigate(FilePathName) Gui, Add , Link, xs yp+120, % "IP Data" . "" ; For latitude, longitude map ; Gui, Add , Link, yp+15, % WhereIs[2] } } Else WhereIs := "No IPs Found!" Clipboard := OldClipboard Gui, Add, Button,xm section, Close Gui, Show,,IP Locations Google Maps (CTRL+Scroll to zoom) Return GetLocation(findip) { UrlDownloadToFile, % "https://tools.keycdn.com/geo?host=" . findip, iplocate IPsearch := "https://tools.keycdn.com/geo?host=" . findip whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") whr.Open("GET", IPsearch) whr.Send() sleep 100 version := whr.ResponseText RegExMatch(version, "s)Location

(.*?)Time", Location) FileRead, version2, iplocate RegExMatch(version, "Coordinates
(.*?) \(lat\) / (.*?)\(long\)", Map) Map := Map1 . "," . Map2 ; For OpenStreetMap MapLink := "Map" . "" MapGet := "https://www.openstreetmap.org/?mlat=" . map1 . "&mlon=" . map2 . "#map=5/" . Map1 . "/" . Map2 ; Strip out HTML tags Location := RegExReplace(Location1,"<.+?>") ; For Google Map Return [Location,Map] ; For OpenStreetMap ; Return [Location,MapLink,MapGet] } ButtonClose: WinClose Return GuiClose: Gui, Destroy Return