Jump to content
Fivewin Brasil

Testar o PING da SEFAZ de SAMPA não funciona.


kapiaba

Recommended Posts



Galera, ajuda ai, o que esta errado?



#include "fivewin.ch"

// PRUEBA DE PING //

FUNCTION Testar_Ping() // DA SEFAZ SAO PAULO - NAO FUNCIONA, O QUE ESTA ERRADO?

if WSAStartup() != 0
MsgAlert( "WSAStartup error" )
return nil
endif

// funciona perfecto - Com ou sem IP fixo do Adhemar do Forum Inter
/*
if hb_Ping( GetHostByName( "www.lostajiboshotel.com" ) ) == 0
Msginfo("Resposta Correta do Host: " + AllTrim( GetHostByName( "www.lostajiboshotel.com" ) ), " Atencao" )
else
Msginfo("Host Inacessivel, Sem Internet: " + AllTrim( GetHostByName( "www.lostajiboshotel.com" ) ), " Atencao" )
endif

Ping( GetHostByName( "www.lostajiboshotel.com" ) )
*/

// NAO FUNCIONA COM O HOST DA SEFAZ SAO PAULO, PORQUE? O Q ESTA ERRADO?

if hb_Ping( GetHostByName( "hom.sefazvirtual.fazenda.gov.br" ) ) == 0

Msginfo("Resposta Correta do Host: " + AllTrim( GetHostByName( "hom.sefazvirtual.fazenda.gov.br" ) ), " Atencao" )

else

Msginfo("Host Inacessivel, Sem Internet: " + AllTrim( GetHostByName( "hom.sefazvirtual.fazenda.gov.br" ) ), " Atencao" )

endif

Ping( GetHostByName( "hom.sefazvirtual.fazenda.gov.br" ) )

WSACleanUp()

return nil

Function Ping(DestinationAddress)

Local IcmpHandle,Replicas,puerto
Local RequestData :="Provando ping",;
RequestSize :=15,;
RequestOptions:="",;
ReplyBuffer :=SPACE(278),;
ReplySize :=278,;
Timeout := 1000 && Milisegundos de espera

DEFAULT DestinationAddress := "127.0.0.1"

DestinationAddress:=LEFT(ALLTRIM(DestinationAddress)+SPACE(15),15)

MsgGet("Teste Sua Internet(Ping)", "Digite um IP Valido: ",@DestinationAddress)

IcmpHandle:= IcmpCreateFile()

Replicas := IcmpSendEcho(IcmpHandle,;
inet_addr(DestinationAddress),;
RequestData,;
RequestSize,0,;
ReplyBuffer,;
ReplySize,;
Timeout)

IcmpCloseHandle(IcmpHandle)

IF Replicas > 0
Msginfo("Resposta correta do host: "+ALLTRIM(DestinationAddress),"Atencao")
ELSE
Msginfo("Host Inacessivel(IP): "+ALLTRIM(DestinationAddress)+"Atencao")
ENDIF

Return nil
//
DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "wsock32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "wsock32.dll"
DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
DestinationAddress AS LONG,;
RequestData AS STRING,;
RequestSize AS LONG,;
RequestOptions AS LONG,;
ReplyBuffer AS LPSTR,;
ReplySize AS LONG,;
Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"

#pragma BEGINDUMP
#include <hbapi.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <icmpapi.h>

int hb_Ping( const char * cp )
{
HANDLE hIcmpFile;
unsigned long ipaddr;
DWORD dwRetVal;
char SendData[32] = "Data Buffer";
LPVOID ReplyBuffer;
DWORD ReplySize;

ipaddr = inet_addr( cp );
if (ipaddr == INADDR_NONE)
return 1;

hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE)
return 2;

ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData);
ReplyBuffer = (VOID*) malloc(ReplySize);
if (ReplyBuffer == NULL)
return 3;


dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData),
NULL, ReplyBuffer, ReplySize, 1000);

if (dwRetVal == 0)
return 4;

return 0;

}


HB_FUNC( HB_PING )
{
hb_retni( hb_Ping( hb_parc( 1 ) ) );
}

#pragma ENDDUMP


Link to comment
Share on other sites

Funcao enviada por Vagner Wirts, em: 07/01/2014

Todos os direitos reservados.



#include "FiveWin.ch"

FUNCTION Main()

cOpc := PegaStatusNoSefaz()

If cOpc == "1" // ; Ativo

? [SEFAZ Ativa]

ElseIf cOpc == "2" // ; em alerta

? [SEFAZ em Alerta]

Else //; Sefaz com problemas

? [SEFAZ com Problemas]

Endif

RETURN NIL

/*********************************************************
* Função : PegaStatusNoSefaz() - Pegar Status do Sefaz para envio da NFe
* Data : 15/08/2011 - 13:25:42 Por : Vagner
* Revisado em : 15/08/2011 - 13:25:44 Por : Vagner
* Parâmetros :
**********************************************************/
Func PegaStatusNoSefaz()

Local oDlg, oAct

lDownload := .F.

lError := .F.

If IsInternet() == .F.

Retu("3")

EndIf

/*
aControls := oWnd:aControls
AEval(aControls,{|x| LogFile("Controles.Txt",x)})
*/

cView := "http://www.nfe.fazenda.gov.br/portal/disponibilidade.aspx?versao=2.00&tipoConteudo=Skeuqr8PQBY="

Define Dialog oDlg From 0,0 To 002,280 Pixel Title "[ Sefaz - Verificando Status ]" Style WS_POPUP

// oDlg:lSkin := .T. // interno do Vagner

// oDlg:cCorSkin := "Marrom" // interno do Vagner

Activate Dialog oDlg NoWait Center

oAct := TActivex():New(oDlg,"Shell.Explorer",680,680,664,600)
nSeconds := Seconds()+30
oAct:bOnEvent := {|cEv|If(cEv=="DownloadComplete",DownloadComplete( oAct ),Nil)}
oAct:Silent := .T.
oAct:Navigate2( "http://www.nfe.fazenda.gov.br/portal/disponibilidade.aspx?versao=2.00&tipoConteudo=Skeuqr8PQBY=" )
oAct:SetFocus()

While !lDownload

If !IsWindowVisible( oDlg:hWnd )

lDownload := .T.
lError := .T.
cError := "Consulta Cancelada !"

ElseIf !IsInternet()

lDownload := .T.

lError := .T.
cError := "Perda de conexao com a internet !"

ElseIf Seconds() > nSeconds

lDownload := .T.
lError := .T.
cError := "Não consegui pegar os dados da página !"

EndIf

SysRefresh()

End

Try

cRetorno := oAct:Document:Body:InnerHtml

Catch oE

lError := .T.
cError := "Falha no recebimento dos dados!"

End

oAct:Destroy()
oDlg:End()
SysRefresh()

If lDownload .and. !lError

Return PegaStatusSefaz( cRetorno)

EndIf

Return("3")

/*********************************************************
* Função : DownloadComplete() - Executa o Download Completo da Página
* Revisado em : 31/01/2012 - 11:10:38 Por : Vagner
* Parâmetros :
* oAct - Objeto Active X
**********************************************************/
Static Func DownloadComplete( oAct )

Local cHTTP := oAct:LocationURL

If ( cView == cHTTP )

If At("tabelaListagemDados",oAct:Document:Body:InnerHtml) != 0
oAct:oWnd:Hide()
lDownload := .T.
Endif

EndIf

Return Nil

/*********************************************************
* Função : PegaStatusSefaz() - Função para pegar as informações do html
* Revisado em : 15/08/2011 - 13:26:59 Por : Vagner
* Parâmetros :
* cSintegra - Texto do html
**********************************************************/
Static Function PegaStatusSefaz(cSintegra)

Local cLine, nLine, nTotal
Local cTex
Local nPos
Local cString
Local aTexto
Local nQtd,cRet

cString := RemoveChar( cSintegra, {"&","amp;","nbsp;",'<!-- ',' -->','<--','-->','||','\/','<!--%','%-->',[/\]} )
cString := cSintegra

nPos := At("<TD>SP</TD>",cString)
cString := Right(cString,Len(cString)-(nPos-1))

nPos := At("<TR class=",cString)
cString := SubStr(cString,1,(nPos-1))

nTotal := MLCount( cString )

aTexto := {}

For nLine := 1 To nTotal
cLine := Alltrim(MemoLine(cString,,nLine))
AaDd(aTexto,cLine)
Next

nQtd := Len(aTexto)

cTex := aTexto[nQtd-1]

If cTex == "-" ; cTex := "0" ; Endif

nTMedi := Val(cTex)

cTex := UPPER(aTexto[2])

If "VERDE" $ cTex ; cRet := "1"

ElseIf "AMARE" $ cTex ; cRet := "2"

Else ; cRet := "3"

Endif

Retu(cRet)

/*********************************************************
* Função : RemoveChar() -
* Revisado em : 15/08/2011 - 13:26:59 Por : Vagner
* Parâmetros :
**********************************************************/
Function RemoveChar(cString,aChar)

Aeval(aChar,{|cChar|cString:=StrTran(cString,cChar)})

Return(cString)

FUNCTION IsInternet()

LOCAL pSocket, lOk := .F.

INetInit()

// funciona perfecto - Com ou sem IP fixo do Adhemar do Forum Inter
pSocket := INetConnect( "www.lostajiboshotel.com", 80 )

// ? INetAddress( pSocket )

IF INetAddress( pSocket ) != "0.0.0.0" // IP retornou .F.
lOk := .T.
ELSE // Se falhar, tentar de novo
pSocket := INetConnect( "www.hotmail.com", 80 )
IF INetAddress( pSocket ) != "0.0.0.0"
lOk := .T.
ELSE // Se falhar, tentar de novo
pSocket := INetConnect( "www.google.com", 80 )
IF INetAddress( pSocket ) != "0.0.0.0"
lOk := .T.
ENDIF
ENDIF
ENDIF

// Fecha o IP verificado para detectar a Internet
INetClose( pSocket )
INetCleanUp()

RETURN( lOk )


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...