#define uint unsigned int
#define uchar unsigned char
void delay(uint z)
sbit LE=P1^4
uchar code table[]={
0xfc,0x60,0xda,0xf2,
0x66,0xb6,0xbe,0xe0,
0xfe,0xf6,0xee,0x3e,
0x9c,0x7a,0x9e,0x8e
}
void 桐余main()
{
uchar temp
uint num
while(1)
{
P2=0xfe //按键扫描第一行衡芦
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
delay(10) //消抖
temp=P2
temp=temp&0xf0
while(temp!=0xf0) //再次确认是否有键按下
{
temp=P2
switch(temp)
{
case 0xee:num=0break
case 0xde:num=1break
case 0xbe:num=2break
case 0x7e:num=3break
}
while(temp!=0xf0) //松手检测
{
temp=P2
temp=temp&0xf0
}
delay(10) //消抖
LE=1
P0=table[num]
LE=0
P1=0x0f
}
}
P2=0xfd //按键扫描第二行
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
delay(10)
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P2
switch(temp)
{
case 0xed:num=4break
case 0xdd:num=5break
case 0xbd:num=6break
case 0x7d:num=7break
}
while(temp!=0xf0)
{
temp=P2
temp=temp&局拦滚0xf0
}
delay(10)
LE=1
P0=table[num]
LE=0
P1=0x0f
}
}
P2=0xfb //按键扫描第三行
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
delay(10)
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P2
switch(temp)
{
case 0xeb:num=8break
case 0xdb:num=9break
case 0xbb:num=10break
case 0x7b:num=11break
}
while(temp!=0xf0)
{
temp=P2
temp=temp&0xf0
}
delay(10)
LE=1
P0=table[num]
LE=0
P1=0x0f
}
}
P2=0xf7 //按键扫描第四行
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
delay(10)
temp=P2
temp=temp&0xf0
while(temp!=0xf0)
{
temp=P2
switch(temp)
{
case 0xe7:num=12break
case 0xd7:num=13break
case 0xb7:num=14break
case 0x77:num=15break
}
while(temp!=0xf0)
{
temp=P2
temp=temp&0xf0
}
delay(10)
LE=1
P0=table[num]
LE=0
P1=0x0f
}
}
}
}
void delay(uint z) //延时子函数
{
uint x
for(zz>0z--)
for(x=1000x>0x--)
}
for(int i=0i<6i++){
for(int j=0j<10j++)
{
theport[j].rmt_host=rmt_host
theport[j].p=port[i*10+j]
theport[j].n=j
Thread[j]=AfxBeginThread(pScan,(LPVOID)&theport[j])
//启动端口扫描线程
hThread[j]=Thread[j]->m_hThread
Sleep(1)
}
WaitForMultipleObjects(10,hThread,TRUE,120000)
}
//扫描模块代码
SOCKET sockfd
SOCKADDR_IN addr
sockfd = socket(AF_INET, SOCK_STREAM, 0)
if (sockfd <0)
{
exit(0)
}
addr.sin_family = AF_INET
addr.sin_port = htons(port)
addr.sin_addr.s_addr = inet_addr(rmt_host)
int r = connect(sockfd,(struct sockaddr *) &addr, sizeof(addr))
//尝试连接端口进行检测
closesocket(sockfd)
//连接返仿搜回值处理
if (r!=-1)
{
::PostMessage(hWnd,WM_DISPLAY,port,0)
}
//显示端口颤大扫描结果
LONG CScanDlg::OnDisplay(LONG lParam, UINT wParam)
{
LPSERVENT bar
CString open
int p=lParam
bar = getservbyport(htons(p),"tcp")
open.Format("备洞历\t%d号端口(%s)开放!\r\n",p,(bar == NULL) ? "未知" :
bar->s_name)
m_HistoryEdit.AppendString (open)
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)