Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

geoloc: new script

  • Loading branch information...
commit 97e84579608c99cc9f3146850405405bbe7e4c22 1 parent e006d33
@falconindy authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 geoloc
View
37 geoloc
@@ -0,0 +1,37 @@
+#!/bin/gawk -f
+
+function getcoord(string, a) {
+ split(string, a, ":")
+ gsub(/\"/, "", a[2])
+ return a[2]
+}
+
+function httpget() {
+ host = "geoiplookup.wikimedia.org"
+ socket = "/inet/tcp/0/" host "/80"
+
+ printf "GET / HTTP/1.1\r\nHost: %s\n\n", host |& socket
+ for (header in headers) {
+ printf "%s\r\n", headers[header] |& socket
+ }
+ printf "\r\n" |& socket
+
+ NR = 0
+ in_body = 0
+ while (socket |& getline) {
+ if (/^\r$/) {
+ socket |& getline
+ return $0
+ }
+ }
+}
+
+BEGIN {
+ data = httpget()
+
+ split(data, coords, /,/)
+ lat = getcoord(coords[3])
+ lon = getcoord(coords[4])
+
+ printf "http://maps.google.com/maps?q=%s,%s\n", lat, lon
+}
Please sign in to comment.
Something went wrong with that request. Please try again.