【2629】Identity Card 【比较坑 / 水题】

这段代码主要用于解析中国身份证号码,并根据前两位地区代码映射到对应的省份。程序读取输入的身份证数量,然后逐个解析,将地区转换为对应的省份名称,同时输出生日信息。身份证的地区码中,例如'33'代表'浙江','82'代表'澳门'等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

http://acm.hdu.edu.cn/showproblem.php?pid=2629

地区只要看前两位就可以了,因为地区是个大的概念后面的数字代表的是县

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void)
{
	int n; cin>>n;
	while(n--)
	{
		string s; cin>>s;
		string area=s.substr(0,2);
		string year=s.substr(6,4);
		string month=s.substr(10,2);
		string day=s.substr(12,2);
		if(area=="33") area="Zhejiang";
		if(area=="82") area="Macao";
		if(area=="11") area="Beijing";
		if(area=="54") area="Tibet";
		if(area=="71") area="Taiwan";
		if(area=="21") area="Liaoning";
		if(area=="81") area="Hong Kong";
		if(area=="31") area="Shanghai";
		cout<<"He/She is from "<<area;
		cout<<",and his/her birthday is on ";
		cout<<month<<","<<day<<","<<year<<" based on the table."<<endl;
	}
	return 0;
}
jingle@pc-ly:~/jzAlgo$ ssh -vvv [email protected].226.115 -p 15567 OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug2: resolve_canonicalize: hostname 183.60.226.115 is address debug2: ssh_connect_direct debug1: Connecting to 183.60.226.115 [183.60.226.115] port 15567. debug1: Connection established. debug1: identity file /home/jingle/.ssh/id_rsa type -1 debug1: identity file /home/jingle/.ssh/id_rsa-cert type -1 debug1: identity file /home/jingle/.ssh/id_dsa type -1 debug1: identity file /home/jingle/.ssh/id_dsa-cert type -1 debug1: identity file /home/jingle/.ssh/id_ecdsa type -1 debug1: identity file /home/jingle/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/jingle/.ssh/id_ecdsa_sk type -1 debug1: identity file /home/jingle/.ssh/id_ecdsa_sk-cert type -1 debug1: identity file /home/jingle/.ssh/id_ed25519 type -1 debug1: identity file /home/jingle/.ssh/id_ed25519-cert type -1 debug1: identity file /home/jingle/.ssh/id_ed25519_sk type -1 debug1: identity file /home/jingle/.ssh/id_ed25519_sk-cert type -1 debug1: identity file /home/jingle/.ssh/id_xmss type -1 debug1: identity file /home/jingle/.ssh/id_xmss-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5 kex_exchange_identification: read: Connection reset by peer
最新发布
03-20
<think>嗯,用户运行了一个ssh命令,连接时被重置了,需要分析原因。首先,用户的命令是ssh -vvv [email protected].226.115 -p 15567,这里用了三个-v参数,说明开启了最详细的调试信息。输出显示到了连接建立之后,但在密钥交换阶段被对方重置了。 接下来看输出内容。OpenSSH版本是8.2p1,系统是Ubuntu,可能对应的OpenSSL版本是1.1.1f。在连接过程中,客户端尝试了各种身份验证文件,比如id_rsa、id_dsa等,但都没有找到,所以使用的是默认的或者没有密钥的情况。然后本地版本字符串发送后,对方回复了一个连接重置,导致kex_exchange_identification失败。 可能的原因有几个方面。首先是端口问,用户指定了非默认的15567端口,可能服务器没在这个端口上监听,或者防火墙阻止了。然后是SSH服务配置问,比如服务器端的SSH配置可能限制了IP、用户,或者使用了不兼容的协议版本。还有可能客户端的SSH版本与服务器不兼容,比如服务器只支持旧版的SSH协议,而客户端用了新版本。另外,也有可能是服务器应用层直接拒绝了连接,比如端口被占用,或者服务未运行。 需要用户检查的步骤包括确认端口是否正确,使用telnet或nc测试端口连通性;检查服务器端SSH服务是否在指定端口运行,配置是否正确;查看服务器日志,如/var/log/auth.log,获取更多拒绝信息;尝试降低SSH协议版本,比如使用-o选项指定协议2或1;以及检查防火墙设置,是否有入站规则限制。如果这些都没问,可能需要联系服务器管理员确认配置。 另外,用户可能不太熟悉网络调试工具,可能需要指导他们如何用telnet或nc,或者如何查看服务器日志。还有可能用户没有权限访问服务器日志,这时候只能建议他们联系管理员。也有可能用户输入了错误的端口号,或者服务器临时不可用,需要再次确认。</think>以下是对该SSH连接过程的逐层分析及问排查建议: --- ### 一、命令解析 执行的命令是: ```bash ssh -vvv [email protected].226.115 -p 15567 ``` - **参数说明**: - `-vvv`:启用最高级别的调试模式(输出详细连接日志) - `[email protected].226.115`:尝试以用户`climb`登录IP为`183.60.226.115`的主机 - `-p 15567`:指定非默认SSH端口`15567` --- ### 二、关键日志分析 #### 1. 客户端初始化阶段 ```log OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 debug1: Reading configuration data /etc/ssh/ssh_config ``` - **客户端版本**:OpenSSH 8.2(较新版本) - **加密库**:OpenSSL 1.1.1f(支持TLS 1.3) #### 2. 密钥认证尝试 ```log debug1: identity file /home/jingle/.ssh/id_rsa type -1 ... debug1: identity file /home/jingle/.ssh/id_xmss type -1 ``` - **问**:客户端尝试加载所有默认私钥文件(如`id_rsa`, `id_ed25519`等),但均未找到(`type -1`表示文件不存在) - **影响**:若服务端要求密钥认证,连接会失败(但当前错误与此无关) #### 3. 连接建立与中断 ```log debug1: Connection established. kex_exchange_identification: read: Connection reset by peer ``` - **关键错误**:TCP连接已建立,但密钥交换阶段被服务端强制关闭 - **错误码解读**:`Connection reset by peer`表示服务端主动拒绝或终止了连接 --- ### 三、可能原因及排查步骤 #### 1. 端口或防火墙问 - **检查端口状态**: ```bash telnet 183.60.226.115 15567 # 或使用 nc -zv 183.60.226.115 15567 ``` - 若无法连通:说明端口未开放或被防火墙拦截 - 若显示`SSH-2.0-xxx`:端口正常但协议不兼容 #### 2. 服务端配置问 - **常见配置限制**: - `sshd_config`中`AllowUsers`未包含`climb` - `Port 15567`未在服务端配置 - 协议版本不匹配(如服务端仅支持SSHv1) - **强制使用SSHv2**: ```bash ssh -o Protocol=2 [email protected].226.115 -p 15567 ``` #### 3. 服务端日志检查 - **登录服务端**(需权限)查看日志: ```bash tail -f /var/log/auth.log # Ubuntu/Debian系统 ``` #### 4. 服务端进程状态 - **确认SSH服务运行**: ```bash sudo netstat -tulpn | grep 15567 ``` --- ### 四、典型解决方案 1. **验证端口开放**: - 联系服务器管理员确认端口`15567`已开放 - 检查本地防火墙规则(如`ufw`或`iptables`) 2. **协议兼容性测试**: ```bash ssh -1 [email protected].226.115 -p 15567 # 强制使用SSHv1(不建议) ``` 3. **简化连接命令**: ```bash ssh -o PreferredAuthentications=password [email protected].226.115 -p 15567 ``` --- ### 五、流程图总结 $$ \begin{CD} \text{客户端发起连接} @>>> \text{TCP三次握手} @>>> \text{SSH协议协商} \\ @. @. @VVV \\ @. @. \text{服务端拒绝(RESET)} \\ \end{CD} $$ 建议按上述步骤逐步排查,优先验证端口可达性和服务端配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值