Custom Script to Return Remote IP

Can someone help me with this script? The IP address will be displayed in the ip_logged_in field but i somehow I will not be able to save the document. (e.g. i click on save, and nothing happens)

cur_frm.cscript.punch_in = function(doc) {
      function(json) {
	doc.ip_logged_in = json.ip;
	doc.time_in = new Date();


Check your JS console, there must be some error