Jump to content
Sign in to follow this  
Phaethon

Simple Network Manipulation

Recommended Posts

Phaethon

Hello everyone! I am wanting to use AutoIt to make a simple program to manipulate my internet connection. However, I have not used AutoIt in some time and don't really know to start with this, nor do I know if it is even possible to do in this language.

Here are the parameters for my project.

  • Grab all current incoming IP addresses on a user button click
  • Deny all connections except those from the aforementioned IP addresses and some predefined IP ranges for a specified period of time

If anyone could give me some guidance on how to go about this, it would be very appreciated.


Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites
Phaethon

The port that all if this relates to is 3074 by the way. UDP.

Edited by Phaethon

Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites
Phaethon

I don't mean to spam, but I am still rather stuck on this. Starting to think it isn't even possible in AutoIt...


Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites
Drakthor

Hello everyone! I am wanting to use AutoIt to make a simple program to manipulate my internet connection. However, I have not used AutoIt in some time and don't really know to start with this, nor do I know if it is even possible to do in this language.

Here are the parameters for my project.

  • Grab all current incoming IP addresses on a user button click
  • Deny all connections except those from the aforementioned IP addresses and some predefined IP ranges for a specified period of time

If anyone could give me some guidance on how to go about this, it would be very appreciated.

http://www.autoitscript.com/autoit3/docs/f...ons/TCPRecv.htm

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
   
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc  ;==>SocketToIP

Then just do something along the lines if If NOT $ip Then etc.

I hope I understood you right.

Share this post


Link to post
Share on other sites
Phaethon

Yes, I looked into this function in the documentation already.

However, I am having trouble getting it to return anything besides 0.


Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites
Drakthor

Yes, I looked into this function in the documentation already.

However, I am having trouble getting it to return anything besides 0.

Global $ip;Ip to listen on
Global $ip2;Ip you expect to connect
Global $port;port to listen on
Global $sock[2]
Global $sockip;Returned IP of the socket

TCPStartup()

$sock[0] = TCPListen($ip,$port)

Do
$sock[1] = TCPAccept($sock[0])
Until $sock[1] <> -1

While 1
$sockip = SockettoIP($sock[1])
If $sockip <> $ip2 Then
TCPCloseSocket($sock[1])
EndIf
Wend

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
  
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc ;==>SocketToIP

This might work, I'm not at my computer so I cannot test.

Share this post


Link to post
Share on other sites
Phaethon

Global $ip;Ip to listen on
Global $ip2;Ip you expect to connect
Global $port;port to listen on
Global $sock[2]
Global $sockip;Returned IP of the socket

TCPStartup()

$sock[0] = TCPListen($ip,$port)

Do
$sock[1] = TCPAccept($sock[0])
Until $sock[1] <> -1

While 1
$sockip = SockettoIP($sock[1])
If $sockip <> $ip2 Then
TCPCloseSocket($sock[1])
EndIf
Wend

Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
  
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc;==>SocketToIP

This might work, I'm not at my computer so I cannot test.

I'm testing this now, however won't this only return 1 IP address? I am expecting to get multiple, and then store them so that I can check against them later.

I want to know all of the IP addresses currently connected (on port 3074), store all of those (probably 4 of them) and then deny all other incoming connections for 10 seconds (BESIDES those 4 IP addresses and 3 other IP ranges) and after that, allow all connections again. I'm sorry if this is confusing lol.


Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites
Phaethon

Just got back to my computer. Still not able to get this to work in any capacity....


Coder's Helper >> Here[center][/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.