JS obtains the IP address, and the console prompts that returnCitySN is undefined

Problem : When using Sohu's IP address query interface https://pv.sohu.com/cityjsonxto obtain the IP address, the console reports an error: returnCitySN未定义.
Solution : You can obtain the IP by adding a timestamp after the link:
https://pv.sohu.com/cityjsonx?timestamp='+new Date().getTime()+'
this method can normally obtain the IP address, and then further processing. This section of processing can be placed directly in HTML.

Here is the full code:

<script>document.write('<script src="https://pv.sohu.com/cityjsonx?timestamp='+new Date().getTime()+'" charset="utf-8"><\/script>');</script>
<script type="text/javascript">
	var Ip = returnCitySN['cip'];
	var cityname = returnCitySN['cname'];
	localStorage.setItem('Ip', Ip);
	localStorage.setItem('cityname', cityname);
</script>

up to date

This interface of Sohu can no longer be used normally, and another interface must be replaced. You can refer to this article:
The front end obtains the user ip through the Tencent interface

Guess you like

Origin blog.csdn.net/qq_28255733/article/details/125530440