當前位置:首頁 » 編程語言 » c語言掃描程序

c語言掃描程序

發布時間: 2023-11-29 13:34:12

1. 100分求linuxc語言埠掃描代碼

linux tcp udp 埠掃描源程序
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <netinet/ip_icmp.h>
#include <stdlib.h>
#include <signal.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#define TRUE 1
#define FALSE 0
#define UDP "UDP"
#define TCP "TCP"
#define tcp "tcp"
#define udp "udp"
typedef struct _GsSockStru{

int fd;
int len;

struct sockaddr_in addr;

}GsSockStru;

static int tcptest( char ip[32], char port[20]);
static int udptest( char ip[32], char port[20]);
void sig_alrm( int signo );

static GsSockStru test_sock;
int
main( int argc, char** argv)
{
char string[64];
char port[20];
char pro[20];
char ip[32];
int res;
int i = 0;
int k = 0;

if( argc>2 || argc<2 )
{
printf("鍙傛暟涓嶆紜?-1\n");
return ( -1 );
}

strcpy( string, argv[1]);

while( *string )
{
if( string[i] == ':' )
break;
pro[k] = string[i];
k++;
i++;
}
pro[k] = '\0';
i++;
k = 0;
while( *string )
{
if( string[i] == ':')
break;
ip[k] = string[i];
k++;
i++;
}
ip[k] = '\0';
i++;
k=0;
while( *string )
{
if( string[i] == '\0')
break;
port[k] = string[i];
k++;
i++;
}
port[k] = '\0';
i++;

memset( &test_sock, 0, sizeof( test_sock ) );
if ( ( strcmp( TCP, pro) != 0 ) && ( strcmp( UDP, pro) != 0 ) && ( strcmp( tcp, pro) != 0 ) && ( strcmp( udp, pro) != 0 ))
{
printf ( "鍙傛暟涓嶆紜?錛?\n" );
return (-1);
}
if ( strcmp( TCP, pro) == 0 || strcmp( tcp, pro) == 0 )
res = tcptest( ip, port );
if ( strcmp( UDP, pro) == 0 || strcmp( udp, pro) == 0 )
res = udptest( ip, port );printf("%d\n",res);
return ( res );
}
int
tcptest( char ip[32], char port[20])
{
int res;
struct timeval tv;

test_sock.fd = socket( AF_INET, SOCK_STREAM, 0 );
if ( test_sock.fd < 0 )
{
printf( "create socket failed -3 \n" );
return ( -3 );
}
memset( &( test_sock.addr ), 0, sizeof( test_sock.addr ) );

test_sock.addr.sin_family = AF_INET;
test_sock.addr.sin_port = htons( atoi( port ) );
inet_pton( AF_INET, ip, &test_sock.addr.sin_addr );
test_sock.len = sizeof( struct sockaddr );
tv.tv_sec = 10;
tv.tv_usec = 0;
setsockopt( test_sock.fd, SOL_SOCKET, SO_RCVTIMEO,
(const char *)&tv, sizeof( tv ) );
res = connect( test_sock.fd,
( struct sockaddr * )( &( test_sock.addr ) ),
test_sock.len );
if ( res < 0 )
{
fprintf( stderr, "connect failed 0\n" );
close( test_sock.fd );
return FALSE;
}
close( test_sock.fd );
return TRUE;
}
int udptest( char ip[32], char port[20])
{
struct icmphdr *icmp_header;
struct sockaddr_in target_info;
int target_info_len;
fd_set read_fd;
int scan_port;
char recvbuf[5000];
struct sockaddr_in target_addr;
int icmp_socket;
int udp_socket;
struct timeval tv;

icmp_header = (struct icmphdr *)(recvbuf+sizeof(struct iphdr));
scan_port = atoi( port );
target_addr.sin_family = AF_INET;
inet_pton( AF_INET, ip, &target_addr.sin_addr );
target_addr.sin_port = htons(scan_port);

if ((udp_socket=socket(AF_INET,SOCK_DGRAM,0))==-1)
{
printf("create socket failed -3\n");
return -3;
}
if ((icmp_socket=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP))==-1)
{
printf("Create raw socket failed -3\n");
return -3;
}

sendto(udp_socket,NULL,0,0,(void *)&target_addr,sizeof(target_addr));
FD_ZERO(&read_fd);
FD_SET(icmp_socket,&read_fd);

tv.tv_sec = 1;
tv.tv_usec = 0;
select(FD_SETSIZE,&read_fd,NULL,NULL,&tv);
for (;;){
if (FD_ISSET(icmp_socket,&read_fd))
{
target_info_len = sizeof(target_info);
recvfrom(icmp_socket,recvbuf,5000,0,
(struct sockaddr *)&target_info,&target_info_len);
if (target_info.sin_addr.s_addr == target_addr.sin_addr.s_addr
&& icmp_header->type == 3 && icmp_header->code<=12)
{
printf("Port %d : Close\n",scan_port);
return (0);
}
}
return (1) ;
}
}

2. 尋單片機「經典鍵盤」的掃描程序(要C語言的)

uchar keyscan()
{
uchar key,i,keyscan;
P3=0x3d; //准備讀取P3.2~P3.5 51的I/0為准雙向I/0口 作為輸入是最好先將其置1
//讀取接地按鍵值
if((P1&0x3d)!=0x3d){ //若無按鍵按下 P3.2~P3.5為高
delay(); //延時去抖動
if((P1&0x3d)!=0x3d){//判斷哪個按鍵按下
key=P1&0x3d;
return key;
}
}

keyscan=0x3D;
for(i=0;i<4;i++){
P1=keyscan; //輸出I/O口掃描 輸出 判斷
if(P1!=keyscan){ //讀取I/O口,看輸出掃P1.0~P1.5的值是否與掃描不同
key=P1&0x3D; //轉換掃描碼
return key;
}
keyscan=(keyscan<<1)|0x01; //逐行輸出掃描 0
}
return 0;
}

3. 設計並實現TINYC語言的掃描程序;

介面:FactorialImp抽象類:FactorialAbs實現計算階乘n!的類:Fatorial代碼:/** * * 階乘計算器 * * 介面 */public interface FactorialImp {// 計算階乘n!的值long factorial(int n);}/** * * 階乘計算器 * * 抽象類 繼承 FactorialImp */public abstract class FactorialAbs implements FactorialImp {/** * 實現計算階乘n!的值的方法 */public long factorial(int n) {return multiplicationCount(n, n - 1);}/世蘆** * 增加抽象方法--計算兩數相乘 * * @param param1Int * @param param2Int * @return 兩數相乘的積 */abstract long multiplicationCount(long param1Int, long param2Int);}/沒如** * 實現階乘計算器類 * */public class Fatorial extends FactorialAbs {@Overridelong multiplicationCount(long param1Int, long param2Int) {if (param2Int == 1) {return param1Int;} else {return multiplicationCount(param1Int * param2Int, param2Int - 1);}}}/** * 測枯返啟試類 * */public class Test {public static void main(String[] args) {Fatorial localFatorial = new Fatorial();System.out.println("100! = " + localFatorial.factorial(10));}}

4. C51 4*4鍵盤掃描程序(c語言)

鍵盤為4*4矩陣式連接,一共有16個按鍵。 工作原理為。P1端的低四位為列,高四位行。所先置低四位為低,高四位為高,當有按鍵按下時高四位就會有某位被拉低。只要判斷高四位不為全高就說明有按鍵按下。判斷有按鍵按下後就要判斷是某位按下的,方法為,選將高四位的某一位置低。判斷低四位是否有低電平出現。依次對高四位的每位置低並判斷低四位出現的低電平。如高四位某位置低後低四某也有出現低電平。這樣就能判斷出低四位與高四位相連的位某位按鍵被按下了。通過定義好的編碼就可以查出是某個按鍵被按下了,程序將按鍵值通過查表並發送到LED上顯示。 6位LED為動態掃描方式 。先顯示第一位,延時一定時間後在顯示第二位依次類推。。。 共有17個按鍵。按下按鍵後數碼管顯示相應的數字,並左移一位。uchar kbscan(void) /*鍵掃描函數*/{uchar j; uchar sccode,recode; P2=0x0f; /*發0行掃描碼*/ if((P2 & 0x0f)!= 0x0f) /*若有鍵按下*/ { dlms(); if((P2&0x0f)!= 0x0f) /*逐行掃描初值*/ { sccode=0xfe; for(j=4;j>0;j--) { while((sccode&0x10)!=0) { P2=sccode; /*輸出行掃描碼*/ if((P2&0xf0)!=0xf0) /*本行有鍵按下*/ { recode=(P2&0xf0)|0x0f; return((~sccode)+(~recode)); /*返回特徵位元組碼*/ } else sccode=(sccode<<1)|0x01; /*行掃描碼做移一位*/ } } } } return(0); /*無鍵按下,返回0值*/}參考鏈接: http://www.picavr.com/news/2008-07/6869.htm

熱點內容
伺服器關閉了電腦網路還能用 發布:2025-01-25 08:22:28 瀏覽:587
熱血航線的登錄密碼在哪裡可以看 發布:2025-01-25 08:22:27 瀏覽:769
5系怎麼選擇配置 發布:2025-01-25 08:22:18 瀏覽:842
pythonscipy 發布:2025-01-25 08:18:52 瀏覽:418
恕瑞瑪伺服器地址 發布:2025-01-25 08:18:51 瀏覽:801
oa源碼php 發布:2025-01-25 08:11:31 瀏覽:734
gpc腳本 發布:2025-01-25 08:10:47 瀏覽:317
雲伺服器和伺服器的區別 發布:2025-01-25 08:10:39 瀏覽:547
python寫文件追加 發布:2025-01-25 08:09:54 瀏覽:778
ftp跳到瀏覽器 發布:2025-01-25 08:09:54 瀏覽:528