Сеть в PowerShell

Содержание
Введение
Открытые порты
Проверить открыт ли порт
Открыть порт
Get-NetIPConfiguration: информация о сети
Разрешить RDP подключения
Статус OpenSSH сервера
Запустить sshd
hostname: Узнать имя хоста
Скачать файл
Похожие статьи

Введение

Это статья про работу с сетью в PowerShell

Изучить темы связанные с сетью в Windows вы можете здесь

Общую информацию о сетях и протоколах можете найти в статье «Компьютерные сети»

Открытые порты

Get-NetTcpConnection

Get-NetTcpConnection PowerShell изображение с сайта www.eth1.ru

Установка Ubuntu

Только порты, которые слушаются в данный момент

Get-NetTcpConnection -State Listen

Get-NetTcpConnection State Listen PowerShell изображение с сайта www.eth1.ru

Установка Ubuntu

Проверить открыт ли порт

Проверить открыт ли конкретный порт на удалённом хосте можно с помощью Test-NetConnection

Пример с портом 8080, открытым для Jenkins

Test-NetConnection 10.30.200.116 -port 8080

ComputerName : 10.30.200.116 RemoteAddress : 10.30.200.116 RemotePort : 8080 InterfaceAlias : Ethernet 6 SourceAddress : 10.30.200.115 TcpTestSucceeded : True

Если порт закрыт

Test-NetConnection 10.30.200.116 -port 8082

WARNING: TCP connect to (10.30.200.116 : 8082) failed

ComputerName : 10.30.200.116 RemoteAddress : 10.30.200.116 RemotePort : 8082 InterfaceAlias : Ethernet 6 SourceAddress : 10.30.200.115 PingSucceeded : True PingReplyDetails (RTT) : 5 ms TcpTestSucceeded : False

Открыть порт

Чтобы открыть порт 22 для доступа по SSH выполните

New-NetFirewallRule -DisplayName "Allow SSH" -Profile "Private" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22

Открыть порт в PowerShell изображение с сайта www.eth1.ru

Установка Ubuntu
Banner image

Получить информацию о сети

Ближайший аналог ipconfig из обычного cmd это Get-NetIPConfiguration

PS C:\Users\Andrei> Get-NetIPConfiguration

InterfaceAlias : vEthernet (Default Switch) InterfaceIndex : 33 InterfaceDescription : Hyper-V Virtual Ethernet Adapter IPv4Address : 172.24.128.1 IPv6DefaultGateway : IPv4DefaultGateway : DNSServer : fec0:0:0:ffff::1 fec0:0:0:ffff::2 fec0:0:0:ffff::3 InterfaceAlias : WiFi InterfaceIndex : 8 InterfaceDescription : Intel(R) Dual Band Wireless-AC 8265 NetProfile.Name : Lester2.4G IPv4Address : 192.168.0.105 IPv4DefaultGateway : 192.168.0.1 DNSServer : 192.168.0.1 InterfaceAlias : Bluetooth Network Connection InterfaceIndex : 11 InterfaceDescription : Bluetooth Device (Personal Area Network) NetAdapter.Status : Disconnected InterfaceAlias : Local Area Connection InterfaceIndex : 13 InterfaceDescription : TAP-ProtonVPN Windows Adapter V9 NetAdapter.Status : Disconnected InterfaceAlias : Ethernet InterfaceIndex : 4 InterfaceDescription : Intel(R) Ethernet Connection (4) I219-V NetAdapter.Status : Disconnected

Разрешить RDP подключения

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0

Разрешить соединение в Firewall

Enable-NetFirewallRule -DisplayGroup "Remote Desktop"

Статус OpenSSH сервера

Проверить статус сервера

Get-Service sshd

Статус OpenSSH сервера в PowerShell изображение с сайта www.eth1.ru

Установка Ubuntu

Запустить OpenSSH сервер

Start-Service sshd

Get-Service sshd

Статус OpenSSH сервера в PowerShell изображение с сайта www.eth1.ru

Установка Ubuntu

hostname

Узнать имя хоста можно командой

hostname

Andrei0123

Скачать файл

Скачать файл можно командой Invoke-WebRequest.

Пример скрипта, который скачивает thrift-0.19.0.exe и сохраняет его как thrift.exe

$THRIFT_URL = "https://dlcdn.apache.org/thrift/0.19.0/thrift-0.19.0.exe" $FilePath = ".\thrift.exe" If (Test-Path -path $FilePath -PathType Leaf) { Write-Host "thrift.exe file exists" -f Green } Else { Write-Host "thrift.exe file does not exist - starting download" -f Yellow Invoke-WebRequest $THRIFT_URL -OutFile thrift.exe }

Article author: Andrei Olegovich

Похожие статьи
Windows
PowerShell
Посмотреть конец файла в PowerShell (аналог tail)
Создать новый файл в PowerShell (аналог touch)
Проверить контрольную сумму файла в PowerShell (аналог md5sum)

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: