Java程序:

import java.net.InetAddress;
import java.net.URL;
import java.util.Scanner;

public class GetIPByPhoneNum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入手机号码:");
        String phoneNum = scanner.nextLine();
        String urlStr = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=" + phoneNum;
        try {
            URL url = new URL(urlStr);
            Scanner urlScanner = new Scanner(url.openStream());
            String result = "";
            while (urlScanner.hasNext()) {
                result += urlScanner.nextLine();
            }
            urlScanner.close();
            String[] segments = result.split(",");
            String ipStr = segments[segments.length - 1].replaceAll("\"|\\\\", "");
            InetAddress address = InetAddress.getByName(ipStr);
            System.out.println("对方IP地址:" + address.getHostAddress());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Python程序:

import json
import requests

def get_ip_by_phone_num(phone_num):
    url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=" + phone_num
    try:
        response = requests.get(url)
        result = response.text.split("=")[1].strip().strip(";")
        data = json.loads(result)
        ip_str = data["isp"].split(" ")[0]
        ip_address = socket.gethostbyname(ip_str)
        print("对方IP地址:" + ip_address)
    except Exception as e:
        print("获取IP地址失败:" + str(e))

if __name__ == '__main__':
    phone_num = input("请输入手机号码:")
    get_ip_by_phone_num(phone_num
在公网上根据手机号获取对方IP用Java和python各写一个程序

原文地址: https://www.cveoy.top/t/topic/eDvS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录